android - lazy load in an expandable list view with over 30 thousand items -
- i looking solution handle 30,000 groupitems using infinite scroll or lazy load within expandable list view? how implement mycustomadapter?
the items loaded local .txt file array , populated expandable list.
- how handle filter many items because on each keydown app freezes, depending on device use.
here customadapter:
public class mycustomadapter extends baseexpandablelistadapter { private layoutinflater inflater; private arraylist<parent> mparent; private static final string tag = "mycustomadapter: "; private static final boolean debug = true; private arraylist<parent> arraylist; context acontext; public mycustomadapter(context context, arraylist<parent> parent){ mparent = parent; inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); this.arraylist = new arraylist<>(); this.arraylist.addall(parent); } @override //counts number of group/parent items list knows how many times calls getgroupview() method public int getgroupcount() { return mparent.size(); } @override //counts number of children items list knows how many times calls getchildview() method public int getchildrencount(int i) { return mparent.get(i).getarraychildren().size(); } @override //gets title of each parent/group public object getgroup(int i) { return mparent.get(i).gettitle(); } public object getgroupname(int i){ return mparent.get(i).getname(); } @override //gets name of each item public object getchild(int i, int i1) { return mparent.get(i).getarraychildren().get(i1); } @override public long getgroupid(int i) { return i; } @override public long getchildid(int i, int i1) { return i1; } @override public boolean hasstableids() { return true; } @override //in method must set text see parent/group on list public view getgroupview(int groupposition, boolean isexpanded, view view, viewgroup viewgroup) { viewholder holder = new viewholder(); holder.groupposition = groupposition; if (view == null) { view = inflater.inflate(r.layout.list_item_parent, viewgroup, false); } parent item = mparent.get(groupposition); //if (debug)log.e(tag, "selected text: " + (item.getname())); textview nametext = (textview) view.findviewbyid(r.id.namevalue); nametext.settext(item.getname()); textview countrylanguagegenretext = (textview) view.findviewbyid((r.id.countrylanguagegenre)); countrylanguagegenretext.settext(item.getcountrylanguagegenre()); view.settag(holder); //return entire view return view; } @override //in method must set text see children on list public view getchildview(int groupposition, int childposition, boolean islastchild, view view, viewgroup viewgroup) { viewholder holder = new viewholder(); holder.childposition = childposition; holder.groupposition = groupposition; if (view == null) { view = inflater.inflate(r.layout.list_item_child, viewgroup, false); } textview textview = (textview) view.findviewbyid(r.id.list_item_text_child); textview.settext(mparent.get(groupposition).getarraychildren().get(childposition)); view.settag(holder); //return entire view return view; } @override public boolean ischildselectable(int i, int i1) { return true; } @override public void registerdatasetobserver(datasetobserver observer) { /* used make notifydatasetchanged() method work */ super.registerdatasetobserver(observer); } protected class viewholder { protected int childposition; protected int groupposition; protected button button; } // filter class public void filter(string chartext) { chartext = chartext.tolowercase(locale.getdefault()); mparent.clear(); if (chartext.length() == 0) { mparent.addall(arraylist); } else { (parent wp : arraylist) { if (wp.getsearchstring().tolowercase(locale.getdefault()).contains(chartext)) { mparent.add(wp); } } } notifydatasetchanged(); } }
one of qualities of list view gets recycled , recreated visible list items. problem not length of items in list view. inefficiency of reading file.
i suggest use database backed design give application more stability can filters working.
Comments
Post a Comment