Skip to content Skip to sidebar Skip to footer

How To Pull Data From Database And View Them As A Listview

I am using a custom list adapter for my ListView. My each list item has 4 items. which are come from a listArray. Here is the code which pull the list items from List Array. i

Solution 1:

You can create a sql query e.g.:

StringsqlQuery="select name,phone,mobile,email from SBL_Contact";

Then use it with a cursor to get the results:

CursorcontactsCursor= database.rawQuery(sqlQuery, null);

and then iterate through your cursor:

ContactItem newsData = null;

while (contactsCursor.moveToNext()) {
       newsData = new ContactItem();
       newsData.setName(contactsCursor.getString(0));
       newsData.setPhone(contactsCursor.getString(1));
       newsData.setMobile(contactsCursor.getString(2));
       newsData.setEmail(contactsCursor.getString(3));

       listMockData.add(newsData);
    }

Post a Comment for "How To Pull Data From Database And View Them As A Listview"