朋友們,我使用AutoCompleteTextView。該建議:如何使用AutoCompleteTextView下拉列表中的seletedItem?
String[] recipes={ "Fish", "Chicken", "Mutton"};
如何做到這一點:
當我從下拉列表中的項目之一,它會去到另一個事件?
例如,I型網絡,它會從下拉列表中走出來魚,然後我選擇魚,它會去另一個活動。
package net.learn2develop.Activities;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.AdapterView;
import android.view.View;
import android.content.Intent;
public class AutoCompleteTextActivity extends Activity {
String[] recipes ={
"Nasi Lemak With Ikan Bilis",
"Steamed Cod Fish"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, recipes);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.txtRecipes);
textView.setThreshold(3);
textView.setAdapter(adapter);
textView.setOnItemSelectedListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> av, View view, int index, long id){
Intent i=new Intent(this,Activity2.class);
i.putExtra("item",recipes[index]);
StartActivity(i);
}
});
}
}
我對setOnItemSelectedListener錯誤..我有進口的財產以後? – user1438955
你有什麼錯誤!如果你將光標指向紅線,你將會看到錯誤。 –
錯誤顯示:在類型AutoCompleteTextView的方法setOnItemSelectedListener(AdapterView.OnItemSelectedListener)不適用於參數(新OnItemClickListener {}) – user1438955