lundi 28 mars 2016

Displayed all Fetched data SQLite

Hi I have this code which retrieves data from the SQLite local database I have created.

the code below is a public cursor which retrieves all the data i require from the database

public Cursor RetriveAdvertData (DatabasOpperations DBOpp, String Username, String AdvertType){
    SQLiteDatabase SQDB = DBOpp.getReadableDatabase();
    String[] Coloumns = {TableData.TableInfo.USERNAME, TableData.TableInfo.ADVERT_NAME, TableData.TableInfo.ADVERT_EMAIL, TableData.TableInfo.ADVERT_ADDRESS, TableData.TableInfo.ADVERT_NUMBER, TableData.TableInfo.ADVERT_TYPE};
    String Where = TableData.TableInfo.USERNAME + " LIKE ? AND " + TableData.TableInfo.ADVERT_TYPE + " LIKE ?";
    String Argument[] = {Username, AdvertType};
    Cursor Cur = SQDB.query(TableData.TableInfo.TABLE_NAME2, Coloumns, Where, Argument, null, null, null);
    return Cur;
}

I then call that Cursor in another java page

Context Contx = this;
public DatabasOpperations DB = new DatabasOpperations(Contx);
public Cursor Cur;
Cur = DB.RetriveAdvertData(DB, DBUsername, "Restaurant");

String AdName = "";
String AdEmail = "";
String AdAddress = "";
String AdNumber = "";
String AdType = "";

if (Cur.moveToFirst()){
            do {
                AdName = Cur.getString(Cur.getColumnIndex("AdvertsName"));
                AdEmail = Cur.getString(Cur.getColumnIndex("AdvertEmail"));
                AdAddress = Cur.getString(Cur.getColumnIndex("AdvertAddress"));
                AdNumber = Cur.getString(Cur.getColumnIndex("AdvertNumber"));
                AdType = Cur.getString(Cur.getColumnIndex("AdvertType"));

                final String[] Adverts = new String[]{
                        AdName, AdEmail, AdAddress, AdNumber, AdType
                };

                ArrayAdapter setListAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Adverts);
                LV1.setAdapter(setListAdapter);
            }while (Cur.moveToNext());
        }
        Cur.close();

the code does display only one row from the database, how do i amend the code to display all the rows in the database?

Aucun commentaire:

Enregistrer un commentaire