这是我的自定义适配器的代码,我的listview填充了mysql数据,但在edittext中搜索显示零结果。
lst=(ListView) findViewById(R.id.listViews);
search = (EditText) findViewById(R.id.search);
items=new ArrayList<Client_information>();
adapter=new Client_storeAdapter(getApplicationContext(),items);
lst.setAdapter(adapter);
Thread thread=new Thread(doInBackground);
thread.start();
search.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
adapter.getFilter().filter(cs);
adapter.notifyDataSetChanged();
Log.d("hello", "hello");
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { }
@Override
public void afterTextChanged(Editable arg0) {}
});
}
Runnable doInBackground=new Runnable()
{
@Override
public void run()
{
items = Client_service.getAllRadioclient(myValue);
runOnUiThread(runOnUi);
}
};
Runnable runOnUi=new Runnable()
{
@Override
public void run()
{
for(Client_information radioitems:items)
{
adapter.add(radioitems);
}
adapter.notifyDataSetChanged();
}
};
}
这是我的自定义适配器的代码,我的listview填充了mysql数据,但在edittext中搜索显示零结果。
答案 0 :(得分:0)
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
MainActivity.this.adapter.getFilter().filter(cs);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
});
在Manifest.xml中
android:windowSoftInputMode="stateHidden"
像这样
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:windowSoftInputMode="stateHidden">