android - Application crashes when searching data from listview using filterable -


i try write application library. have activity, see books in stock. use listview, , baseadapter. information saved in database.

oncreate in activity:

    @override     protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_crown_library_details);      // initialization value     member = (member) getintent().getserializableextra(intentextra.member.tostring());     book = (book) getintent().getserializableextra(intentextra.book.tostring());     title = (textview) findviewbyid(r.id.title);     author = (textview) findviewbyid(r.id.author);     title.settext(book.gettitle());     author.settext(book.getauthor());     searchview = (searchview) findviewbyid(r.id.searchview);     listview = (listview) findviewbyid(r.id.listview);     new asynctask<void, void, void>() {         @override         protected void onpreexecute() {         }          @override         protected void doinbackground(void... voids) {             bookshoparraylist = backend.getallshopofbookid(book.getbookid());             cart = backend.getcart(member.getmemberid());             if (member.isshop())                 bookshopshopeditionadapter = new bookshop_shopeditionadapter(crownlibrarydetails.this,                         bookshoparraylist, member.getmemberid(), book.getbookid(), accesstype.shop);             else                 bookshopshopeditionadapter = new bookshop_shopeditionadapter(crownlibrarydetails.this,                         bookshoparraylist, member.getmemberid(), book.getbookid(), accesstype.member);             bookshopshopeditionadapter.addlistener(crownlibrarydetails.this);             return null;         }          @override         protected void onpostexecute(void list) {             listview.setadapter(bookshopshopeditionadapter);         }     }.execute();      // menu     getsupportactionbar().setdisplayhomeasupenabled(true);     getsupportactionbar().sethomebuttonenabled(true);     getsupportactionbar().settitle(r.string.title_activity_crown_library);      listview.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview<?> adapterview, view view, int i, long l) {             if (member.isshop()) {                 intent intent = new intent(crownlibrarydetails.this, bookdetailsforshop.class);                 intent.putextra(intentextra.book_shop.tostring(), bookshopshopeditionadapter.getitem(i));                 intent.putextra(intentextra.previous_activity.tostring(), intentextra.crown_library_details.tostring());                 intent.putextra(intentextra.member.tostring(), member);                 startactivity(intent);             } else {                 intent intent = new intent(crownlibrarydetails.this, bookdetailsformember.class);                 intent.putextra(intentextra.book_shop.tostring(), bookshopshopeditionadapter.getitem(i));                 intent.putextra(intentextra.member.tostring(), member);                 intent.putextra(intentextra.previous_activity.tostring(), intentextra.crown_library_details.tostring());                 startactivity(intent);             }          }     });      searchview.setonquerytextlistener(new searchview.onquerytextlistener() {         @override         public boolean onquerytextsubmit(final string s) {             if (member.isshop())                 bookshopshopeditionadapter = new bookshop_shopeditionadapter(crownlibrarydetails.this,                         bookshoparraylist, member.getmemberid(), book.getbookid(), accesstype.shop);             else                 bookshopshopeditionadapter = new bookshop_shopeditionadapter(crownlibrarydetails.this,                         bookshoparraylist, member.getmemberid(), book.getbookid(), accesstype.member);             bookshopshopeditionadapter.addlistener(crownlibrarydetails.this);             bookshopshopeditionadapter.getfilter().filter(s);             listview.setadapter(bookshopshopeditionadapter);             return false;         }          @override         public boolean onquerytextchange(final string s) {             if (member.isshop())                 bookshopshopeditionadapter = new bookshop_shopeditionadapter(crownlibrarydetails.this,                         bookshoparraylist, member.getmemberid(), book.getbookid(), accesstype.shop);             else                 bookshopshopeditionadapter = new bookshop_shopeditionadapter(crownlibrarydetails.this,                         bookshoparraylist, member.getmemberid(), book.getbookid(), accesstype.member);             bookshopshopeditionadapter.addlistener(crownlibrarydetails.this);             bookshopshopeditionadapter.getfilter().filter(s);             listview.setadapter(bookshopshopeditionadapter);             return false;         }     }); } 

my baseadpater:

 public class bookshop_shopeditionadapter extends baseadapter implements filterable {  arraylist<bookshop> bookshopslist; arraylist<bookshop> searchstoreoredition; layoutinflater inflater; context context; long memberid; long bookid; accesstype accesstype; shop _shop;  private backend backend = backendfactory.getinstance(context);  public bookshop_shopeditionadapter(context context, arraylist<bookshop> list, long memberid, long bookid, accesstype accesstype) {     this.bookshopslist = list;     this.context = context;     inflater = layoutinflater.from(this.context);     this.memberid = memberid;     this.bookid = bookid;     this.accesstype = accesstype; }  @override public filter getfilter() {     return new filter() {         @override         protected filterresults performfiltering(final charsequence constraint) {             filterresults fr = new filterresults();              new asynctask<void, void, void>() {                 @override                 protected void onpreexecute() {                 }                  @override                 protected void doinbackground(void... voids) {                     if (constraint.equals("")) {                         searchstoreoredition = bookshopslist;                     } else {                         (bookshop book_shopitem : bookshopslist) {                             if (backend.getshoptoid(book_shopitem.getshopid()).getshopname()                                     .tolowercase().contains(constraint))                                 searchstoreoredition.add(book_shopitem);                             else if (book_shopitem.getedition().tolowercase().contains(constraint))                                 searchstoreoredition.add(book_shopitem);                         }                     }                      return null;                 }                  @override                 protected void onpostexecute(void avoid) {                 }             }.execute();               fr.count = searchstoreoredition.size();             fr.values = searchstoreoredition;             return fr;          }          @override         protected void publishresults(charsequence constraint, filterresults results) {             if (results != null) {                 bookshopslist = (arraylist<bookshop>) results.values;                 notifydatasetchanged();             }         }     }; }  public interface storeeditionadapterlistener {[...]}  private arraylist<storeeditionadapterlistener> listlistener = new arraylist<>();  public void addlistener(storeeditionadapterlistener alistener){[...]}  private void sendlistenerbuy(bookshop item, int position) {[...]}  private void sendlistenerdelete(bookshop item, int position) {[...]}  @override public int getcount() {[...]}  @override public bookshop getitem(int position){[...]}  @override public long getitemid(int position) {[...]}  @override public view getview(final int position, view convertview, viewgroup parent) {     relativelayout layoutitem;      if (convertview == null) {         layoutitem = (relativelayout) inflater.inflate(r.layout.view_book_shop_shop_edition_adapter, parent, false);     } else {         layoutitem = (relativelayout) convertview;     }      final textview shop = (textview) layoutitem.findviewbyid(r.id.shop);     final textview edition = (textview) layoutitem.findviewbyid(r.id.edition);     final textview format = (textview) layoutitem.findviewbyid(r.id.format);     final textview state = (textview) layoutitem.findviewbyid(r.id.state);     final textview price = (textview) layoutitem.findviewbyid(r.id.price);      imageview deleteicon = (imageview) layoutitem.findviewbyid(r.id.delete);     imageview buyexpressicon = (imageview) layoutitem.findviewbyid(r.id.buyexpressicon);     textview buyexpress = (textview) layoutitem.findviewbyid(r.id.buyexpress);      new asynctask<void, void, void>() {         @override         protected void onpreexecute() {         }          @override         protected void doinbackground(void... voids) {             _shop = new shop(backend.getshoptoid(bookshopslist.get(position).getshopid()));             return null;         }          @override         protected void onpostexecute(void avoid) {             shop.settext(_shop.getshopname());          }     }.execute();       edition.settext(bookshopslist.get(position).getedition());     format.settext(bookshopslist.get(position).getformat().tostring());     state.settext(bookshopslist.get(position).getstate().tostring());     price.settext(string.format("%s$", bookshopslist.get(position).getpricebook()));      if (accesstype.equals(accesstype.director_delete)) {//director         deleteicon.setvisibility(view.visible);         buyexpress.setvisibility(view.gone);         buyexpressicon.setvisibility(view.gone);     } else if (accesstype.equals(accesstype.shop)) {         buyexpress.setvisibility(view.gone);         buyexpressicon.setvisibility(view.gone);         deleteicon.setvisibility(view.gone);     } else         deleteicon.setvisibility(view.gone);      //click     buyexpressicon.settag(position);     buyexpressicon.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             integer position = (integer) v.gettag();             sendlistenerbuy(bookshopslist.get(position), position);         }     });      deleteicon.settag(position);     deleteicon.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {             integer position = (integer) v.gettag();             sendlistenerdelete(bookshopslist.get(position), position);         }     });      return layoutitem; } 

}

at time, writte in searchbar, , call function filter of baseadapter. application stops running, without anyting.

01-21 08:50:51.512 19914-19914/? d/dalvikvm: late-enabling checkjni 01-21 08:50:51.556 19914-19920/? d/dalvikvm: debugger has detached; object registry had 1 entries 01-21 08:50:51.800 19914-19914/? w/dalvikvm: vfy: unable find class referenced in signature (landroid/view/searchevent;) 01-21 08:50:51.804 19914-19914/? i/dalvikvm: not find method android.view.window$callback.onsearchrequested, referenced method android.support.v7.internal.view.windowcallbackwrapper.onsearchrequested 01-21 08:50:51.804 19914-19914/? w/dalvikvm: vfy: unable resolve interface method 18302: landroid/view/window$callback;.onsearchrequested (landroid/view/searchevent;)z 01-21 08:50:51.804 19914-19914/? d/dalvikvm: vfy: replacing opcode 0x72 @ 0x0002 01-21 08:50:51.808 19914-19914/? i/dalvikvm: not find method android.view.window$callback.onwindowstartingactionmode, referenced method android.support.v7.internal.view.windowcallbackwrapper.onwindowstartingactionmode 01-21 08:50:51.808 19914-19914/? w/dalvikvm: vfy: unable resolve interface method 18306: landroid/view/window$callback;.onwindowstartingactionmode (landroid/view/actionmode$callback;i)landroid/view/actionmode; 01-21 08:50:51.808 19914-19914/? d/dalvikvm: vfy: replacing opcode 0x72 @ 0x0002 01-21 08:50:51.844 19914-19914/? i/dalvikvm: not find method android.content.res.resources.getdrawable, referenced method android.support.v7.internal.widget.resourceswrapper.getdrawable 01-21 08:50:51.844 19914-19914/? w/dalvikvm: vfy: unable resolve virtual method 780: landroid/content/res/resources;.getdrawable (ilandroid/content/res/resources$theme;)landroid/graphics/drawable/drawable; 01-21 08:50:51.844 19914-19914/? d/dalvikvm: vfy: replacing opcode 0x6e @ 0x0002 01-21 08:50:51.844 19914-19914/? i/dalvikvm: not find method android.content.res.resources.getdrawablefordensity, referenced method android.support.v7.internal.widget.resourceswrapper.getdrawablefordensity 01-21 08:50:51.844 19914-19914/? w/dalvikvm: vfy: unable resolve virtual method 782: landroid/content/res/resources;.getdrawablefordensity (iilandroid/content/res/resources$theme;)landroid/graphics/drawable/drawable; 01-21 08:50:51.844 19914-19914/? d/dalvikvm: vfy: replacing opcode 0x6e @ 0x0002 01-21 08:50:51.888 19914-19917/? d/dalvikvm: gc_concurrent freed 195k, 3% free 10932k/11207k, paused 11ms+1ms, total 20ms 01-21 08:50:51.944 19914-19914/? d/libegl: loaded /system/lib/egl/libegl_genymotion.so 01-21 08:50:51.944 19914-19914/? d/: hostconnection::get() new host connection established 0xb80b6c50, tid 19914 01-21 08:50:51.956 19914-19914/? d/libegl: loaded /system/lib/egl/libglesv1_cm_genymotion.so 01-21 08:50:51.956 19914-19914/? d/libegl: loaded /system/lib/egl/libglesv2_genymotion.so 01-21 08:50:52.024 19914-19914/? w/egl_genymotion: eglsurfaceattrib not implemented 01-21 08:50:52.036 19914-19914/? d/openglrenderer: enabling debug mode 0 01-21 08:50:52.300 19914-19914/? d/openglrenderer: texturecache::get: create texture(0xb80c93b8): name, size, msize = 4, 2200, 2200 01-21 08:50:52.356 19914-19914/? d/openglrenderer: texturecache::get: create texture(0xb80c7fe0): name, size, msize = 5, 2200, 4400 01-21 08:50:52.540 19914-19914/? d/openglrenderer: texturecache::get: create texture(0xb80e30f0): name, size, msize = 11, 4096, 8496 01-21 08:50:52.588 19914-19914/com.example.lilo.ebookstore i/choreographer: skipped 32 frames!  application may doing work on main thread. 

its not required set adapter on again in querytextlistener. if filter working, don't have except :

searchview.setonquerytextlistener(new searchview.onquerytextlistener() {         @override         public boolean onquerytextsubmit(final string s) {              return false;         }          @override         public boolean onquerytextchange(final string s) {             bookshopshopeditionadapter.getfilter().filter(s);         bookshopshopeditionadapter.notifydatasetchanged();             return false;         }     }); 

also don't need run asynctask in filter filtering.

example using filter in listview :

http://www.survivingwithandroid.com/2012/10/android-listview-custom-filter-and.html


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -