AndroidアプリケーションでAutoCompleteTextViewを使用したかったのですが、文字列の単純な配列でAutoCompleteTextViewを使用する方法は知っていますが、AutoCompleteTextViewでオブジェクトのリストを使用して補完を実行したいと思いました。このためのコードは次のとおりです。
アクティビティコード
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
initialize();
ArrayAdapter<Student> adapter = new ArrayAdapter<Student>(this,
R.layout.dropdown_list_item, GetAllStudentsList());
searchBox.setAdapter(adapter);
searchBox.setThreshold(THRESHOLD_VALUE);
searchBox.setTextColor(Color.BLACK);
}
searchBox.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view,
int position, long arg3) {
//Here i will grab the Student object that user selected from drop-down
}
});
public ArrayList<Movies> GetAllStudentsList() {
//This method returns a ArrayList of <Student> type objects
}
学生クラスオブジェクトには、である学生に関する情報がありID,NAME,ADDRESS,MARKS
ます。
AutoCompleteTextViewが検索操作を実行するためにString型オブジェクトの配列を必要とすることを知っています。私の場合、AutoCompleteTextViewがStudentオブジェクトフィールドNAMEに基づいて補完を実行するためにArrayListを使用するようにしたいです。AutoCompleteTextViewを指定してのNAMEフィールドを使用する方法がわかりません。学生オブジェクト。リンクまたは小さな例を提供するのを手伝ってください。
ありがとう