我是Android開發的新手,目前我面臨着我的項目的問題,我想將我的應用程序連接到本地主機,我已經看到了如何做到這一點,並拿起最簡單的使用JSON,因此我停下來實現我的TextWatcher
將其添加到該代碼的方式。剩下的事情,我已經做了,因爲它需要在步驟。如何在我的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"/>
編輯的代碼沒有工作:( –