java - Android AutoCompleteTextView showing wrong suggestions -


i had autocompletetextview working until decided use custom adapter, way customize of each row. here happens:

enter image description here

as can see, suggestion wrong. happening type, shows correct number of suggestions, actual names of them first ones in list. @ point should show 1 suggestion texas a&m, instead shows first 1 in list. here how implementing adapter.

//setup filter list<string> allcollegeslist = new arraylist<string>(); for(college c : mainactivity.collegelist) {     allcollegeslist.add(c.getname()); } autocompletedropdownadapter adapter = new autocompletedropdownadapter(main, r.layout.list_row_dropdown, allcollegeslist); //the old way of using adapter, worked fine //arrayadapter<string> adapter = new arrayadapter<string>(main, android.r.layout.simple_dropdown_item_1line, allcollegeslist); textview.setadapter(adapter); 

as actual adapter class:

public class autocompletedropdownadapter extends arrayadapter<string>{      mainactivity main;     int rowlayout;     list<string> allcollegeslist;      public autocompletedropdownadapter(mainactivity main, int rowlayout, list<string> allcollegeslist) {         super(main, rowlayout, allcollegeslist);         this.main = main;         this.rowlayout = rowlayout;         this.allcollegeslist = allcollegeslist;     }      @override     public view getview(int position, view convertview, viewgroup parent) {          try{              if(convertview==null){                 // inflate layout                 layoutinflater inflater = ((mainactivity) main).getlayoutinflater();                 convertview = inflater.inflate(rowlayout, parent, false);             }              // object item based on position             string college = allcollegeslist.get(position);              // textview , set text (item name) , tag (item id) values             textview collegetextview = (textview) convertview.findviewbyid(r.id.dropdowntext);             collegetextview.settext(college);             collegetextview.settypeface(fontmanager.light);          } catch (nullpointerexception e) {             e.printstacktrace();         } catch (exception e) {             e.printstacktrace();         }          return convertview;      } } 

what happens here when autocompletetextview calls getfilter method of arrayadapter filter returned, takes care of filtering arrayadapter, not allcollegeslist. when type first characters, methods of filter called , arrayadapter has filtered elements @ first positions (0, 1, ...). when autocompletetextview uses implementation views. use list if no filtering done , use first elements of unfiltered list.

you can filter own list overriding getfilter method of adapter. more coding necessary.

you can use arrayadapter's methods , not own list, instead:

use

string college = getitem(position); 

instead of

string college = allcollegeslist.get(position); 

btw:

you can context parent too, using getcontext() method. way can decouple adapter mainactivity.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -