【发布时间】:2014-05-17 02:55:49
【问题描述】:
创建了一个应用,其中有两个 AutoCompleteTextView。在第一个用户输入他/她想要的食物种类。例如:意大利文、中文等。
如果假设用户在第一个 AutoCompleteTextView 中输入中文,那么第二个 AutoCompleteTextView 应该只建议中国食品。在 strings.xml 中,我创建了一个名为“tastes”的数组,其中包含意大利、中国等不同的口味。然后我有一个名为“Italian”的数组,其中仅包含意大利菜肴,就像一个名为“Chinese”的数组其中仅包含中国菜等。
如果一旦用户在第一个 textview 中输入了他的选择,我如何从 strings.xml 中为第二个 textview 选择相应的数组?
除了 swicth case,我还能用什么?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find);
this.text1 = (AutoCompleteTextView) findViewById(R.id.taste);
String[] tastes = getResources().getStringArray(R.array.tastes);
ArrayAdapter<String> adapterTaste = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, taste);
this.text1.setAdapter(adapterTaste);
this.text1.setThreshold(1);
this.text2 = (AutoCompleteTextView) findViewById(R.id.item);
String[] items = getResources().getStringArray(R.array.Chinese);
// In place of Chinese in the above line, the feed from text1 ie users choice.
ArrayAdapter<String> adapterItem = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, item);
this.text2.setAdapter(adapterItem);
this.text2.setThreshold(1);
}
【问题讨论】:
标签: android arrays autocomplete filtering