AutoCompleteTextView或SearchDialog? [英] AutoCompleteTextView or SearchDialog?
问题描述
我需要做什么都只是关键字的建议,可以点击,带来的用户接口(XML布局)。例如,结果如下遵守,比比皆是,没有。我在R.layout.abide创建它们
What i need to be done are just the suggestions of keywords can be clicked and bring user to the interfaces (xml layout). For example the result below abide, abound, absence. I created them in R.layout.abide
虽然 AutoCompleteTextView
似乎少些麻烦,但能不能做到?还是要做到这一点的唯一方法就是通过 SearchDialog
?我没有使用 SearchWidget
,因为我做的API等级为8。
Though AutoCompleteTextView
seem to be less hassle but can it be done ? Or the only way to do it is through SearchDialog
? I am not using SearchWidget
because i am doing api level 8.
推荐答案
如果我没看错,你想用户只需选择自动完成的项目,一旦他选择了,就应该给你带来另一种activity.if是的话,那么就可以实现它,如下。
If I am not wrong,you want user to just select an item from AutoComplete and once he selects it,it should bring you to another activity.if it is the case then you can achieve it as below.
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.autocomplete_item,options);
// R.layout.autocomplete_item is custom spinner item xml file.you can use default spinner item also.
autoComplete.setAdapter(adapter);
autoComplete.setThreshold(1);
autoComplete.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3) {
Intent intent;
int index=999;
for(int i=0;i<options.length;i++)
{
if(options[i].equals(autoComplete.getText().toString().trim()))
{
index=i;
break;
}
}
switch(index)
{
case 0:
intent=new Intent(ThisActivity.this,ActivityZero.class);
startActivity(intent);
break;
case 1:
intent=new Intent(ThisActivity.this,ActivityOne.class);
startActivity(intent);
break;
...
}
}
});
或者,如果你想留在同一个活动,而是希望根据用户在自动完成,那么你可以的setContentView(你的XML)的选择,以改变它的XML;在对各种选择上述情况。
Or if you want to stay on the same activity but want to change its xml according to the selection user makes in AutoComplete then you can setContentView(your xml); in above cases for various selection.
这篇关于AutoCompleteTextView或SearchDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!