android - How to add Pagination in Expandable list view with Sqlite & Asynctask -
there sqlite database, , experiencing problems paging implementation inside of expandable list view.
i want fetch data (ten records @ time) , display these records in explandable list view.
how can achieve goal via asynctask, doing background interaction server display information database?
main activity
/** count. */ static int count=0; listdataheader = new arraylist<string>(); childdatahashmap = new hashmap<string, list<childinfo>>(); databasehelper = new databasehelper(this); // readfromfile(); csvtosqlite(); // listview explistview = (expandablelistview) findviewbyid(r.id.expandablelistview); txtviewloadmore=(textview) findviewbyid(r.id.textviewloadmore); // loadmore button button btnloadmore = new button(this); btnloadmore.settext("load more"); // adding load more button lisview @ bottom explistview.addfooterview(btnloadmore) txtviewloadmore.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { count = count+1; //call asynctask loading data in expandable list view in background new nearbuyasynctask(mainactivity.this).execute(); } }); getexpandablelistdata(); listadapter = new expandablelistadapter(this, listdataheader,childdatahashmap); // setting list adapter explistview.setadapter(listadapter);
}
public void getexpandablelistdata() { // group data// // databasehelper = new databasehelper(getapplicationcontext());{ cursor cursor; if(count==0) { cursor = databasehelper.getgroupdata(); } else{ cursor = databasehelper.getloadmoredata(count); } cursor.movetofirst(); log.i(tag, "cursor.getcount()" + cursor.getcount()); { string categorydescription = cursor.getstring(cursor.getcolumnindex("categorydesc")); int categoryid = cursor.getint(cursor.getcolumnindex("categoryid")); // child data// cursor cursorchild = databasehelper.getchilddata(categoryid); list<childinfo> childlist = new arraylist<childinfo>(); cursorchild.movetofirst(); while (cursorchild.movetonext()) { string businessname = cursorchild.getstring(cursorchild .getcolumnindex("businessname")); phonenumber = cursorchild.getstring(cursorchild.getcolumnindex("ph_phone")); string landmark = cursorchild.getstring(cursorchild .getcolumnindex("landmark")); childinfo childinfo = new childinfo(businessname, phonenumber, landmark); childlist.add(childinfo); } childdatahashmap.put(categorydescription, childlist); } while (cursor.movetonext()); cursor.close(); }
nearbuyasynctask
@override protected void doinbackground(void... params) { // todo auto-generated method stub activity = new mainactivity(); activity.runonuithread(new runnable() { @override public void run() { // todo auto-generated method stub mainactivity mainactivity = new mainactivity(); mainactivity.getexpandablelistdata(); } }); return null; }
i getting following error
caused by: java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare()
Comments
Post a Comment