У меня есть ListView и EditText. Как я могу фильтровать данные ListView при вводе в EditText?Как фильтровать данные ListView при вводе в EditText в android
Мой код приведен ниже:
public class ListContacts extends ListActivity {
ListAdapter lAdapter;
EditText filterText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Associate the xml with the activity
setContentView(R.layout.activitylist);
Cursor cursor = getContentResolver().query(
ContactsContract.Contacts.CONTENT_URI, null,
null, null,
null);
startManagingCursor(cursor);
// start mappings
String[] columns = new String[] { ContactsContract.Contacts.DISPLAY_NAME };
int[] names = new int[] { R.id.contact_name };
lAdapter = new ImageCursorAdapter(this, R.layout.main, cursor, columns,
names);
/** * фильтровать контакты */
filterText = (EditText) findViewById(R.id.EditText01);
filterText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
}
} // конец класса ListContacts
public class ImageCursorAdapter extends SimpleCursorAdapter {
private Cursor c;
private Context context;
public ImageCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
this.c = c;
this.context = context;
}
public View getView(int pos, View inView, ViewGroup parent) {
}
} // конец класса ImageCursorAdapter
Спасибо за адаптер массива sample.Here используется для установки lsitview. Здесь я использую ListAdapter ... может, пожалуйста, дать мне другое решение. – jennifer
Указанная вами ссылка не работает. Вы не возражаете, отправляя его снова, у меня нет такой же проблемы, но ваш ответ был связан здесь [http://stackoverflow.com/questions/4711459/sorting-data-in-autocompletetextview] – madcoderz
@madcoderz Я исправил проверьте, что – ingsaurabh