listview - Custom adapter Filtering -
i using custom adapter listview, , searchmenu, before using filter gives me correct information
example:
name1 - email1 name2 - email2 name3 - email3
but after using filter searching names correct email column gives 1 row info.
example:
name3 - email1
how can solve problem, im new in java, 5 days work on problem.
customrow adapter
public class custom_row extends arrayadapter<string> { arraylist<string> list; public custom_row(context context, arraylist<string> names, arraylist<string> email) { super(context, r.layout.custom_cell, names); list = email; log.e("database operations", string.valueof(list)); } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater peoinf = layoutinflater.from(getcontext()); view customview = peoinf.inflate(r.layout.custom_cell, parent, false); string names = getitem(position); string email = list.get(position); textview name_text = (textview) customview.findviewbyid(r.id.name_text); textview email_text = (textview) customview.findviewbyid(r.id.email_text); name_text.settext(names); email_text.settext(email); return customview; }
}
main activity
public class mainactivity extends appcompatactivity {
arrayadapter<string> adapter; private listview listview_allcontacts; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); listview_allcontacts = (listview) findviewbyid(r.id.listview_allcontacts); listview_allcontacts.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { intent intent = new intent(mainactivity.this, contactdetailsactivity.class); textview v = (textview)view.findviewbyid(r.id.email_text); string text = listview_allcontacts.getitematposition(position).tostring(); /* bundle b = new bundle(); b.putint("position", position); intent.putextras(b); startactivity(intent);*/ intent.putextra("id", text); intent.putextra("email", v.gettext()); startactivity(intent); toast.maketext(getbasecontext(), v.gettext(), toast.length_long).show(); } }); } @override public boolean oncreateoptionsmenu(menu menu) { menuinflater inflater = getmenuinflater(); inflater.inflate(r.menu.options_menu, menu); inflater.inflate(r.menu.main_menu,menu); final menuitem item = menu.finditem(r.id.menusearch); searchview searchview = (searchview) item.getactionview(); searchview.setonquerytextlistener(new searchview.onquerytextlistener() { @override public boolean onquerytextsubmit(string query) { return false; } @override public boolean onquerytextchange(string newtext) { adapter.getfilter().filter(newtext); return false; } }); return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.menu_new_contact: startactivity(new intent(mainactivity.this, contactdetailsactivity.class)); break; } return super.onoptionsitemselected(item); } @override protected void onresume() { dbhelper db = new dbhelper(this); arraylist<string> names = new arraylist<string>(); arraylist<string> email = new arraylist<string>(); (int = 0; < db.getallcontacts().size(); i++) { names.add(db.getallcontacts().get(i).getname()); email.add(db.getallcontacts().get(i).getemail()); } adapter = new custom_row(this, names, email); // arrayadapter adapter = new custom_row(this, names, email); listview_allcontacts.setadapter(adapter); super.onresume(); } }
Comments
Post a Comment