I wanted to use AutoCompleteTextView in my android application.I know how to use it with simple array of Strings, but I wanted AutoCompleteTextView to use list of Objects to perform completion.My code for this is following:
ACTIVITY CODE
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
}
Student class Object has information regarding a student which is ID,NAME,ADDRESS,MARKS
.
I know AutoCompleteTextView needs an array of String type object to perform search operation.In my case I want AutoCompleteTextView to use my ArrayList to perform completion on the basis of Student object field NAME.I dont know how should I specify AutoCompleteTextView to use NAME field of Student object.Please help me providing any Link or a small example.
Thanks