我的 TextChangedListener 搜索代码不起作用。我在 ListView 中没有任何变化,你能说我的问题在哪里吗?我在这篇文章http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/中读到了它,在其他材料中我也尝试过
list.setTextFilterEnabled(true);
list.setFilterText(s.toString());
但这也行不通
code:
public class SicksListActivity extends Activity implements TextWatcher{
private DBHelper dbHelper;
private SimpleCursorAdapter adapter;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.sickness_list);
displaySicks();
}
private void displaySicks(){
Queries queries=new Queries();
Cursor c=queries.getAllSicks(this);
ListView list=(ListView)findViewById(android.R.id.list);
EditText inputText=(EditText)findViewById(R.id.sick_input_search);
inputText.addTextChangedListener(this);
String [] colums={SicknessDB.NAME};
int [] views={android.R.id.text1};
adapter=new SimpleCursorAdapter(this,
android.R.layout.simple_expandable_list_item_1, c, colums,views);
list.setAdapter(adapter);
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
this.adapter.getFilter().filter(s);
}
}