Здравствуйте, в приведенном ниже коде я реализую функцию поиска. Из Api я разыскиваю имя учетной записи. Для реализации списка я использую recyclerView.
При реализации этой функции я сталкиваюсь с проблемой. ui часть У меня есть edittext и recyclerview.
, когда я ищу 'a', он отображает список, когда я пытаюсь выбрать элемент, он выбирает другой текст, а затем задает какой-то другой текст для текста редактирования.
Где я совершил ошибку, может кто-нибудь мне помочь
searchAccount.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(final CharSequence charSequence, int i, int i1, int i2) {
adapter = new CustomAdapter(account_name);
recyclerViewAccount.setHasFixedSize(true);
recyclerViewAccount.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerViewAccount.setAdapter(adapter);
// editTextSearch.setText("ABC");
recyclerViewAccount.clearFocus();
recyclerViewAccount.addOnItemTouchListener(new RecyclerTouchListener(getContext(), recyclerViewAccount, new RecyclerTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
RecordsAccounts recordsAccounts=recordsListAccount.get(position);
account_id =recordsAccounts.getId();
accountnames =recordsAccounts.getAccountname();
//account_name=recordsAccounts.getAccountname().toString();
Log.e("account_id",account_id);
searchAccount.setText(accountnames);
}
@Override
public void onLongClick(View view, int position) {
}
}));
}
@Override
public void afterTextChanged(Editable editable) {
//after the change calling the method and passing the search input
filter(editable.toString());
}
});
private void filter(String text) {
//new array list that will hold the filtered data
ArrayList<String> filterdNames = new ArrayList<>();
//looping through existing elements
for (String s : account_name) {
//if the existing elements contains the search input
if (s.toLowerCase().contains(text.toLowerCase())) {
//adding the element to filtered list
filterdNames.add(s);
// editTextSearch.setText(text);
}
// editTextSearch.setText(s);
}
//calling a method of the adapter class and passing the filtered list
adapter.filterList(filterdNames);
}