我的Json准备好后如何实现TextWatcher?

时间:2016-03-07 04:52:54

标签: java android

我是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) {

    }
};

}

这是我的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"/>

1 个答案:

答案 0 :(得分:0)

您尚未将textwatcher添加到EditText或任何视图,您要处理哪个文本事件.see http://developer.android.com/reference/android/text/TextWatcher.html 为什么你需要实现将json结束为localhost的textwacther。