android - Empty listview displayed after doing filter operation -
i have dropdown in layout filter listviewes, used onoptionsitemselected method filter listviewes,now filter eventlistviewes using displayeventlist() method.but unfortunately filtered listview not displayed in layout(after filter operation eventlistview filtered may not displayed in layout),please me solve problem.
public boolean onoptionsitemselected(menuitem item) { log.d("onoptionsitemselected", "yes"); switch (item.getitemid()) { case r.id.all: displayeventinvitationlist(inflater, container,savedinstancestate); return true; case r.id.event: displayeventlist(inflater, container,savedinstancestate); return true; case r.id.invitation: displayinvitationlist(inflater, container,savedinstancestate); return true; default: return super.onoptionsitemselected(item); } } public view displayeventlist(layoutinflater inflater, viewgroup container,bundle savedinstancestate) { super.oncreate(savedinstancestate); view = inflater.inflate(r.layout.chatwindow_tab, container, false); context = getactivity().getapplicationcontext(); sharedpreferences = context.getsharedpreferences(constants.shared_preference_name, context.mode_private); databasehelper dbhelper = new databasehelper(context); usermo = dbhelper.getringeeuserdata(1); new asynctask<void, void, list<eventmo>>() { @override protected list<eventmo> doinbackground(void... arg0) { eventmos = gson.fromjson(eventdelegates.getalleventfromuser(usermo, context), new typetoken<list<eventmo>>() { }.gettype()); list<eventmo> groupeventlist = new arraylist<>(); (eventmo eventmo : eventmos) { groupeventlist.add(eventmo); } return groupeventlist;//it returns eventlist } @override protected void onpostexecute(list<eventmo> groupeventlist) { groupeventmolist = groupeventlist; chatdisplayadapter = new chatdisplayadapter(); groupeventview.setadapter(chatdisplayadapter); groupeventview.setitemscanfocus(true); groupeventview.settextfilterenabled(true); groupeventview.setonitemclicklistener(groupeventview.getonitemclicklistener()); } }.execute(null, null, null); return view; } private class chatdisplayadapter extends baseadapter { private layoutinflater minflater; public chatdisplayadapter() { minflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); } @override public int getcount() { return groupeventmolist.size(); } @override public object getitem(int position) { return groupeventmolist.get(position); } @override public long getitemid(int id) { // sqllite management return 0; } @override public view getview(int position, view convertview, viewgroup parent) { if (convertview == null) { convertview = minflater.inflate(r.layout.chatwindow, null); convertview.setclickable(true); convertview.setfocusable(true); chattitle = (textview) convertview.findviewbyid(r.id.chat_title); chatplace = (textview) convertview.findviewbyid(r.id.event_place); chatdate = (textview) convertview.findviewbyid(r.id.event_date); chatplace.settext(groupeventmolist.get(position).getplace()); string actualdate = groupeventmolist.get(position).geteventdate(); //chatdate.settext(groupeventmolist.get(position).geteventdate()); try { //date format changed here date formatdate = new simpledateformat("yyyy-mm-dd").parse(actualdate); dateresult = new simpledateformat("dd-mm-yyyy").format(formatdate); } catch (parseexception e) { e.printstacktrace(); } chatdate.settext(dateresult); chattitle.settext(groupeventmolist.get(position).gettext()); convertview.settag(position); view v = convertview.findviewbyid(r.id.chat_window_single); v.getrootview().setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { log.i("position", v.gettag().tostring()); intent groupact = new intent(context, groupchatactivity.class); groupact.addflags(intent.flag_activity_clear_top); groupact.putextra("eventmo", groupeventmolist.get(integer.parseint(v.gettag().tostring()))); startactivity(groupact); } }); } return convertview; } } }
for filtering set adapter updated list , call notifydatasetchanged() on adpater
chatdisplayadapter chatdisplayadapter =new chatdisplayadapter(groupeventlist); chatdisplayadapter.notifydatasetchanged();
chatdisplayadpater.java
private class chatdisplayadapter extends baseadapter<eventmo> { private layoutinflater minflater; list<eventmo> groupeventmolist; public chatdisplayadapter(list<eventmo> datagroupeventmolist) { minflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); groupeventmolist=datagroupeventmolist; } @override public int getcount() { return groupeventmolist.size(); } @override public object getitem(int position) { return groupeventmolist.get(position); } @override public long getitemid(int id) { // sqllite management return 0; } @override public view getview(int position, view convertview, viewgroup parent) { if (convertview == null) { convertview = minflater.inflate(r.layout.chatwindow, null); convertview.setclickable(true); convertview.setfocusable(true); chattitle = (textview) convertview.findviewbyid(r.id.chat_title); chatplace = (textview) convertview.findviewbyid(r.id.event_place); chatdate = (textview) convertview.findviewbyid(r.id.event_date); chatplace.settext(groupeventmolist.get(position).getplace()); string actualdate = groupeventmolist.get(position).geteventdate(); //chatdate.settext(groupeventmolist.get(position).geteventdate()); try { //date format changed here date formatdate = new simpledateformat("yyyy-mm-dd").parse(actualdate); dateresult = new simpledateformat("dd-mm-yyyy").format(formatdate); } catch (parseexception e) { e.printstacktrace(); } chatdate.settext(dateresult); chattitle.settext(groupeventmolist.get(position).gettext()); convertview.settag(position); view v = convertview.findviewbyid(r.id.chat_window_single); v.getrootview().setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { log.i("position", v.gettag().tostring()); intent groupact = new intent(context, groupchatactivity.class); groupact.addflags(intent.flag_activity_clear_top); groupact.putextra("eventmo", groupeventmolist.get(integer.parseint(v.gettag().tostring()))); startactivity(groupact); } }); } return convertview; } }
Comments
Post a Comment