fragment - Filtering listview data of simple_list_item_2 items using searchview and arrayadapter -
i'm writing android application (min api 14) consists of 3 tabs hold fragment each. 1 of fragments holds list view (with list view item defined simple_list_item_2) , search view. now, i'm trying filter data in list view room's name (room model)
protected searchview searchview; protected listview view; protected list<room> rooms; protected arrayadapter<room> roomadapter; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(getlayoutid(), container, false); view = (listview)rootview.findviewbyid(getlistviewid()); searchview = (searchview)rootview.findviewbyid(r.id.rooms_search_view); view.settextfilterenabled(true); .... roomadapter = new arrayadapter<room>(this.getactivity(), android.r.layout.simple_list_item_2, rooms){ @override public view getview(int position, view convertview, viewgroup parent) { view row; if(convertview == null){ layoutinflater inflater = (layoutinflater)getactivity().getapplicationcontext(). getsystemservice(context.layout_inflater_service); row = (view)inflater.inflate(android.r.layout.simple_list_item_2, null); }else{ row = (view)convertview; } room data = rooms.get(position); textview v = (textview) row.findviewbyid(android.r.id.text1); v.settext(data.getname()); v = (textview) row.findviewbyid(android.r.id.text2); v.settext(data.getphone()); return row; } }; view.setadapter(roomadapter); .... return rootview; } @override public boolean onquerytextchange(string newtext) { roomadapter.getfilter().filter(newtext); return true; }
the problem search results in no way relevant input entered in search view. when replace *android.r.layout.simple_list_item_2* *android.r.layout.simple_list_item* work expected.
i read overriding tostring() method in model(room) solve such problem, didn't work either.
any figuring out how filter title(android.r.id.text1) highly appreciated.
well, after couldn't find solution 'standard' android adapters, ended writing custom adapter extends baseadapter , implements filterable. can find hints in here if encounter same problem.
Comments
Post a Comment