Java 当我的Json就绪时,如何实现TextWatcher?

Java 当我的Json就绪时,如何实现TextWatcher?,java,android,Java,Android,我是Android开发的新手,目前我的项目面临问题,我想将我的应用程序连接到本地主机,我已经看到了实现这一点的方法,并使用json选择了最简单的方法,因此我停止了实现我的TextWatcher并将其添加到代码中。其余的事情,我已经做了,因为它需要的步骤 请看一下我的代码,告诉我我的错误是什么 这是我的Java代码: public class MyActivity extends Activity implements TextWatcher { HttpClient httpClient; pr

我是Android开发的新手,目前我的项目面临问题,我想将我的应用程序连接到本地主机,我已经看到了实现这一点的方法,并使用json选择了最简单的方法,因此我停止了实现我的
TextWatcher
并将其添加到代码中。其余的事情,我已经做了,因为它需要的步骤

请看一下我的代码,告诉我我的错误是什么

这是我的Java代码:

public class MyActivity extends Activity implements TextWatcher {
HttpClient httpClient;
private HttpPost mhttpPost;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    String[] mobileArray = {"Laptops","IPhone","WindowsMobile","Blackberry","WebOS","Ubuntu","Windows7","Max OS X"};
    ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.list_item,mobileArray);
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(adapter);

    httpClient = new DefaultHttpClient();
    mhttpPost = new HttpPost("http://10.0.2.1/index/get_for_mobile");

    try {
        HttpResponse response = httpClient.execute(mhttpPost);
        HttpEntity ent = response.getEntity();
        String temp = EntityUtils.toString(response.getEntity());
    }
    catch (Exception e ){}

}
private TextWatcher search = new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void afterTextChanged(Editable editable) {

    }
};
公共类MyActivity扩展活动实现TextWatcher{
HttpClient-HttpClient;
私有HttpPost-mhttpost;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[]mobileArray={“笔记本电脑”、“IPhone”、“WindowsMobile”、“黑莓”、“WebOS”、“Ubuntu”、“Windows7”、“Max OS X”};
ArrayAdapter=新的ArrayAdapter(此,R.layout.list_项,mobileArray);
ListView ListView=(ListView)findViewById(R.id.ListView);
setAdapter(适配器);
httpClient=新的DefaultHttpClient();
mhttpost=新的HttpPost(“http://10.0.2.1/index/get_for_mobile");
试一试{
HttpResponse response=httpClient.execute(mhttpPost);
HttpEntity ent=response.getEntity();
String temp=EntityUtils.toString(response.getEntity());
}
捕获(例外e){}
}
私有TextWatcher搜索=新TextWatcher(){
@凌驾
更改前的公共无效(CharSequence CharSequence,int i,int i1,int i2){
}
@凌驾
public void onTextChanged(CharSequence CharSequence,int i,int i1,int i2){
}
@凌驾
public void PostTextChanged(可编辑){
}
};
}

下面是我的xml代码:

<!-- The primary full-screen view. This can be replaced with whatever view
     is needed to present your content, e.g. VideoView, SurfaceView,
     TextureView, etc. -->

<!-- This FrameLayout insets its children based on system windows using
     android:fitsSystemWindows. -->
<SearchView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/searchView"

        android:layout_marginBottom="48dp" />

<ListView
        android:layout_width="wrap_content"
        android:layout_height="399dp"
        android:id="@+id/listView"
        android:layout_gravity="right|top"
        android:choiceMode="multipleChoice" android:clickable="true"/>



您尚未将textwatcher添加到EditText或任何视图中,您希望处理哪个文本事件。请参阅
为什么您需要在将json终止到本地主机时实现textwacther。

我需要添加TextWatcher来实现我的SearchView,因为当我键入ip以连接到本地主机时,它不会继续进一步尝试添加完成按钮yourEditText.setImeOptions(EditorInfo.IME\u ACTION\u done);或者android:imeOptions=“actionDone”代替文本监视程序,单击“完成”按钮添加代码到呼叫post请求编辑的代码无效:(