Android - search based on property of AutoCompleteTextView suggestion, or value of AutoCompleteTextView
I have a MyObj class with a name and an id. I have an AutoCompleteTextView that is currently letting you type MyObj names and it auto-completes them for you. There's a button next to the AutoCompleteTextView that, when pressed, I want to:
- initiate a search based on the
idof the selectedMyObj, if one of the auto-complete suggestions开发者_运维知识库 was used, OR - initiate a search based on the value in the
AutoCompleteTextViewif none of the auto-complete suggestions was used (so a partialnamestring).
How should I go about this? I'm new to Android, so suggestions for other ways to do this are very welcome. Here's some of my current code:
AutoCompleteTextView actv = (AutoCompleteTextView)findViewById(R.id.searchText);
ArrayAdapter<MyObj> adapter = new ArrayAdapter<MyObj>(this,
android.R.layout.simple_dropdown_item_1line, myObjectsList);
actv.setAdapter(adapter);
And also:
public void searchButtonOnClick(View view) {
// Don't know how to get id of selected MyObj here, or just the value in the
// AutoCompleteTextView otherwise
}
I ended up creating a search instead of using an AutoCompleteTextView, since the search gives suggestions as you type also. I was able to pass the id along via the URI in an Intent to display another Activity with the MyObj details.
加载中,请稍侯......
精彩评论