です:
AutoCompleteTextView a1 = (AutoCompleteTextView) findViewById(...);
StudentInfo[] s1 = studentInfo.toArray(new StudentInfo[studentInfo.size()]);
ArrayAdapter<StudentInfo> adapter = new ArrayAdapter<StudentInfo>(this, android.R.layout.simple_dropdown_item_1line, s1);
a1.setAdapter(adapter);
a1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View arg1, int position, long arg3) {
Object item = parent.getItemAtPosition(position);
if (item instanceof StudentInfo){
StudentInfo student=(StudentInfo) item;
doSomethingWith(student);
}
}
});
ArrayAdapte rはStudentInfoのtoString()メソッドを使用して表示されたテキストを生成するので、素敵なtoStringメソッドを実装する必要があります。
このように、この種の実装はどのオブジェクトタイプにも適用できます。
ところで:私はandroid.R.layout.simple_spinner_dropdown_item代わりにandroid.R.layout.simple_dropdown_item_1lineを好むモデルクラス(この場合StudenInfo)ためtoString
メソッドをオーバーライド
あなたの中にA1が何でありますかコードとあなたはtextviewまたはedittextで選択したアイテムを撮影したいですか? –
a1はオートコンプリートのテキストビューであり、選択したアイテムをテキストビューに表示したい。 – bhoot4242
オートコンプリートテキストビューに自動的に設定されたアイテムを選択すると、オートコンプリートテキストビューになります。それのために余分な方法を含める必要はありません。ここをクリック:http://dj-android.blogspot.in/2013/04/android-autocompletetextview-inside.html –