android - Retrieve data from database and display them to screen -


i want display data database screen in grip view not working. when ran nothing happens no error or log

here code on mainactivity:

db db = new db(this);      // reading contacts     log.d("reading: ", "reading contacts..");     list<contact> contacts = db.getallcontacts();      (contact cn : contacts) {         string log = "id: "+cn.getid()+" ,name: " + cn.getname() + " ,time: " + cn.gettime();         // writing contacts log         log.d("name: ", log);      }      db.getallcontacts();      gridview = (gridview) findviewbyid(r.id.gridview1);     arrayadapter<string> adapter = new arrayadapter<string>(this,             android.r.layout.simple_list_item_1, arrayofname);     gridview.setadapter(adapter);      gridview.setonitemclicklistener(new adapterview.onitemclicklistener() {         public void onitemclick(adapterview<?> parent, view v,                                 int position, long id) {             toast.maketext(getapplicationcontext(),                     ((textview) v).gettext(), toast.length_short).show();         }     }); 

and here code on db:

//getting contacts1     public list<contact> getallcontacts() {     list<contact> contactlist = new arraylist<contact>();     // select query     string selectquery = "select  * " + table_contacts;      sqlitedatabase db = this.getwritabledatabase();     cursor cursor = db.rawquery(selectquery, null);      // looping through rows , adding list     if (cursor.movetofirst()) {         {             contact contact = new contact();             contact.setid(integer.parseint(cursor.getstring(0)));             contact.setname(cursor.getstring(1));             contact.settime(integer.parseint(cursor.getstring(2)));             // adding contact list             contactlist.add(contact);         } while (cursor.movetonext());     }      // return contact list     return contactlist; } 

i not sure excatly problem believe in mainactivity, in advance!

arrayofname not initialized anywhere, think should fill in first loop. no need second call getallcontacts.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -