我在我的代码中使用了AutoCompleteTextView,并使用SimpleCursorAdapter从数据库中加载列表。
AutoCompleteTextView cocktailIngredientView = (AutoCompleteTextView) findViewById(R.id.item);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item, mCursor,
new String[] { "field" },
new int[] { android.R.id.text1 });
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cocktailIngredientView.setAdapter(adapter);
cocktailIngredientView.setThreshold(0);
它正确地填充了列表,但我有两个问题:
- 我希望这个列表是排序的
- 无论我输入什么,它都会显示完整的列表。我想要基于列表中匹配模式的过滤器。例如,如果列表包含值Page、Tools...那么如果我在框中输入T,下拉框应该只显示Tools。这个想法是显示包含任何字符串文本中输入模式的选项。