android - custom MultiAutoCompleteTextView with drop down -
i have class:
public class multiobjectselectorview extends linearlayout { private list<string> items; private list<string> default_items; private list<string> display_items; private edittext text_feild; private listview drop_down; public multiobjectselectorview(context context, attributeset attrs) { super(context, attrs); layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); inflater.inflate(r.layout.multiobjectselectorlayout, this, true); drop_down = (listview) findviewbyid(r.id.drop_down); text_feild = (edittext) findviewbyid(r.id.mytextview); display_items = new arraylist<string>(); final listadapter adapter = new listadapter(context,display_items); drop_down.setadapter(adapter); text_feild.addtextchangedlistener(new textwatcher() { public void beforetextchanged(charsequence s, int start, int count, int after) { } public void ontextchanged(charsequence s, int start, int before,int count) { if(!s.tostring().equals("")){ display_items = new arraylist<string>(); string str = s.tostring(); for(int = 0;i<items.size();i++){ string[] splited = items.get(i).split("\\s+"); int isfound = 0; for(int x = 0;x<splited.length;x++){ if(splited[x].startswith(str)){ isfound = 1; x = splited.length; } } if(isfound == 1){ display_items.add(items.get(i)); } } }else{ display_items = new arraylist<string>(); } adapter.setlistdata(display_items); adapter.notifydatasetchanged(); } public void aftertextchanged(editable s) { } }); drop_down.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) { } }); } public void setlist(string[] list){ items = new arraylist<string>(); for(int = 0;i<list.length;i++){ items.add(list[i]); } default_items = items; } public void setlist(string[] list,string[] list2){ items = new arraylist<string>(); default_items = new arraylist<string>(); for(int = 0;i<list.length;i++){ items.add(list[i]); } for(int = 0;i<list2.length;i++){ default_items.add(list2[i]); } } public void setlist(string[] list,string[] list2,string[] list3){ items = new arraylist<string>(); default_items = new arraylist<string>(); for(int = 0;i<list.length;i++){ items.add(list[i]); } for(int = 0;i<list2.length;i++){ default_items.add(list2[i]); } for(int = 0;i<list3.length;i++){ items.add(list3[i]); } } private class listadapter extends arrayadapter<string> { private final context context; private list<string> values; public listadapter(context context, list<string> values) { super(context, r.layout.dropdownlayout, values); this.context = context; this.values = values; } public void setlistdata(list<string> values2){ values = values2; } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view rowview = inflater.inflate(r.layout.dropdownlayout, parent, false); textview textview = (textview) rowview.findviewbyid(r.id.drop_down_text_view); textview.settext(values.get(position)); return rowview; } @override public int getcount() { return values.size(); } @override public string getitem(int position) { return values.get(position); } @override public long getitemid(int position) { return position; } } } the reason don't use multiautocompletetextview (1). wanted items in drop down, (2). drop downs not going used auto complete list gives custom suggestions in drop down view(they don't yet, they'll add clicked on list). problem listview, when expanded pushes down below custom viewgroup. overlay else.
also layout file:
sion="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <edittext android:id="@+id/mytextview" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/deit_restr_text" android:ems="10" > </edittext> <listview android:id="@+id/drop_down" android:layout_width="match_parent" android:layout_height="fill_parent" > </listview> </linearlayout>
Comments
Post a Comment