Я использовал android autocompleteTextView с настраиваемым ArrayAdapter.
При касании autocompleteTextView отображается экранная клавиатура: поле «Номер дома и улица» "is autocompleteTextView
После того, как я начал вводить текст, появляется раскрывающийся список и скрывает autocompleTextView: " Номер дома и улица "скрывается раскрывающимся списком
Но когда я прокрутите вверх autocmpleteTextView, который отображается правильно: "Номер дома и улица" не скрываются раскрывающимся списком
Мой пользовательский ArrayAdapter:
public class AutoCompleteAdapter extends ArrayAdapter<String> {
private List<String> items;
private List<String> itemsCopy;
private List<String> itemsResult;
private int viewResourceId;
public AutoCompleteAdapter(Context context, int viewResourceId, List<String> items) {
super(context, viewResourceId, items);
this.items = items;
this.itemsCopy = items;
this.itemsResult = new ArrayList<>();
this.viewResourceId = viewResourceId;
}
@NotNull
public View getView(int position, View convertView, @NotNull ViewGroup parent) {
View view = convertView;
if (view == null) {
LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = layoutInflater.inflate(viewResourceId, null);
}
String product = items.get(position);
if (product != null) {
TextView productLabel = view.findViewById(R.id.text);
if (productLabel != null) {
productLabel.setText(product);
}
}
return view;
}
@NotNull
@Override
public Filter getFilter() {
return nameFilter;
}
private Filter nameFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
if (constraint != null) {
itemsResult.clear();
for (String product : itemsCopy) {
if (product.toLowerCase().startsWith(constraint.toString().toLowerCase())) {
itemsResult.add(product);
}
}
FilterResults filterResults = new FilterResults();
filterResults.values = itemsResult;
filterResults.count = itemsResult.size();
return filterResults;
} else {
return new FilterResults();
}
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
ArrayList<String> filteredList = (ArrayList<String>) results.values;
if (results.count > 0) {
clear();
for (String s : filteredList) {
add(s);
}
notifyDataSetChanged();
}
}
};
}
Даже если я пытаюсь использовать адаптер из android документации, у меня возникает та же проблема:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
Также я попытался добавить в файл манифеста этот код:
windowSoftInputMode="adjustResize"
Но поведение макета становится для меня некорректным.
Кто-нибудь уже сталкивался с этой проблемой? Есть какое-то решение?