plaese see this search in listview...
http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/
سؤال
i have a search functionality for an app i am developing and i implemented a sliding menu. In the sliding menus right view, there is an edit text search box but since my app is an offline app, i want to search a listview using an adapter and not a database, i have implemented my code but when i run it, nothing happens, the logcat gives me no errors as well, can someone pls help me check my code out to see if i have any errors.
public class SearchActivity extends Activity {
private ListView lv;
ArrayAdapter<String> adapter;
EditText inputSearch;
ArrayList<String> testArrayList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu_right);
String [] testArray = getResources().getStringArray(R.array.allArrays);
testArrayList = new ArrayList<String>(Arrays.asList(testArray));
lv = (ListView) findViewById(R.id.listViewMenuRight);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, testArrayList);
lv.setAdapter(adapter);
inputSearch = (EditText) findViewById(R.id.editTextSearch);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
SearchActivity.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
}
});
}
}
المحلول
plaese see this search in listview...
http://www.androidhive.info/2012/09/android-adding-search-functionality-to-listview/