我創建了一個活動,其中有textview/autocompletetextview,listview和一個按鈕。我的autocompletetextview效果很好,但我想將我在textview中輸入的內容編入索引視圖,當它突出顯示時,我會單擊按鈕並轉到相應的活動。Android AutocompleteTextView建議索引到列表視圖
這裏是迄今爲止我所做的事情:
String[] classes = {
"Acornsquash",
"Almonds",
"Apples", }
private ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.nutritional_list);
setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.nutrition32);
//ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
// android.R.layout.simple_dropdown_item_1line, classes);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.my_list_item, classes);
AutoCompleteTextView tv = (AutoCompleteTextView) findViewById (R.id.txtSearcEngine);
tv.setThreshold(3);
tv.setAdapter(adapter);
tv.setTextColor(Color.BLACK);
lv = (ListView) findViewById(R.id.lvListSearch);
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, classes));
lv.setOnItemClickListener(this);
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
lv.setSelection(position);
switch(position)
{
case 0:
Intent acorn = new Intent(Nutritional_List.this, AcornSquash.class);
startActivity(acorn);
break;
case 1:
Intent almonds = new Intent(Nutritional_List.this, Almonds.class);
startActivity(almonds);
break;
我的問題是,我沒有一個線索如何索引建議從autocompletetextview到列表視圖做。任何幫助?謝謝。
你好,我試過你的代碼,但它不工作。 :( – Dunkey
請看我上面更新的帖子^^我收錄了我的onItemClick方法 – Dunkey
嗨,我要爲list,autoIndex和TextView v創建一個局部變量嗎? – Dunkey