android - Filling ListView with AsyncTask (doInBackground() returning cursor) -


i'm trying fill listview using asynctask. included problem in comment

private class downloaddatatask extends asynctask<string, void, cursor> {     private final progressdialog dialog = new progressdialog(ctx);       @override     protected void onpreexecute() {         this.dialog.setmessage(ctx.getstring(r.string.acquiringdata));         this.dialog.show();     }       @override     protected cursor doinbackground(final string... args) {                   dbadapter dbadapter = new dbadapter(ctx);         dbadapter.open();         // when call method main class reurns cursor full of values         cursor cursor = dbadapter.fetchallitemsinexpenses();          return cursor;     }       protected void onpostexecute(final cursor cursor) {         if (this.dialog.isshowing()) {             this.dialog.dismiss();            //cursor empty      } 

ctx context set on main class oncreate()

following requests pasting fetchallitemsinexpenses() method:

public cursor fetchallitemsinexpenses() {     string query = "select ... " //(some terribly boring , long query string, trust me, works fine)     return sqldb.rawquery(query, null); } 

try in asynctask...

private class downloaddatatask extends asynctask<string, void, cursor> {     private final progressdialog dialog = new progressdialog(ctx);     context ctx = null; //add , constructor below      public downloaddatatask(context context) {         ctx = context;     }      ...  } 

then in activity create , execute asynctask follows...

downloaddatatask ddt = new downloaddatatask(this); ddt.execute(theargs); 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -