Display Objects in MultiAutoCompleteTextView
To display object value in MultiAutoCompleteTextView, you have to build a custom adapter:
For example, I have a tag class, which has Id field and name field.
Firstly, you need to have an adapter
Code
public View getView(int position, View convertView, ViewGroup parent) { | |
View v = convertView; | |
Holder holder; | |
if (v == null) { | |
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
v = vi.inflate(R.layout.autocomplete_layout, null); | |
holder= new Holder(); | |
| |
holder.Name=(TextView)v.findViewById(R.id.tagText); | |
convertView = v; | |
convertView.setTag(holder); | |
}else{ | |
holder=(Holder)convertView.getTag(); | |
} | |
Tag tag = items.get(position); | |
if (tag != null) { | |
holder.Name.setText(""+items.get(position).getTitle()); | |
TextView tagLabel = (TextView) v.findViewById(R.id.tagText); | |
if (tagLabel != null) { | |
tagLabel.setText(tag.getTitle()); | |
} | |
} | |
return v; | |
} | |
| |
private class Holder{ | |
| |
| |
public TextView Name; | |
| |
| |
} |
Then you need to change in CreateView at the fragment class
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
List tagList = app.GetTags();
TagAdapter tagAdapter= new TagAdapter((Context)getActivity(),tagList);
multiAutoCompleteTextView.setThreshold(1);
multiAutoCompleteTextView.setAdapter(tagAdapter);
ck -->
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
Feedback awaiting moderation
This post has 42 feedbacks awaiting moderation...
Form is loading...