Skip to content Skip to sidebar Skip to footer

How To Retrieve All The Rows In My DB?

Good day sorry for asking these question. Hope somebody help me solve my problem. Also hoping that my question is clear enough so that somebody will not down vote it. I'm just new

Solution 1:

First you need to iterate in your getUserSLDetails method in your SQLiteHandler class

if (cursor.moveToFirst()) {
    do {
          Datas pMemebr = new Datas();

          pMemebr.setSL_DESC(cursor.getString(0));
          pMemebr.setTR_DATE(cursor.getString(1));
          pMemebr.setACTUAL_BALANCE(cursor.getString(2));
          pMemebr.setAVAILABLE_BALANCE(cursor.getString(3));

          mMemberDetails.add(pMemebr);

          Log.d(TAG, "List<Datas>) Getting members' SL Description:        " + cursor.getString(0));
          Log.d(TAG, "List<Datas>) Getting members' SL TR Date:            " + cursor.getString(1));
          Log.d(TAG, "List<Datas>) Getting members' SL Actual Balance:     " + cursor.getString(2));
          Log.d(TAG, "List<Datas>) Getting members' SL Available Balance:  " + cursor.getString(3));
          Log.d(TAG, "-------------------------------------------------------------------------");

          Log.d(TAG, "List<Datas>) Members's SL Details data:              " + pMemebr.toString());
            } while (cursor.moveToNext());
        }
 cursor.close();
 return mMemberDetails;
}

Then in your MyAdapter you need to change the below method -

@Override
public int getItemCount() {
    //return mDataset.length;
    return mdataset.size();
}

Please do remove the logs once you have verified that your data is coming correctly.


Solution 2:

use do while loop

 if (cursor.moveToFirst()) {
                do {
                    Datas data = new DiaryData(cursor.getString(0), cursor.getString(1), cursor.getString(2), cursor.getString(3)
                            , cursor.getString(4));
                    // Adding data to list
                    mMemberDetails.add(data);
                } while (cursor.moveToNext());
            }
     cursor.close();
    return mMemberDetails;

Solution 3:

you are passing 0 therefore there is no item available so use

@Override
public int getItemCount() {
    //return mDataset.length;
    return mdataset.size();
}

Solution 4:

Right now you're only recovering the first result of your cursor. Check this piece of code you wrote:

if (cursor.getCount() > 0) {
    ...
    mMemberDetails.add(pMemebr);
    ...
}

You're only getting the first and only first item. You need to iterate through the cursor. Instead of doing that if (cursor.getCount() > 0) consider changint to while (cursor.moveToNext())

You can find more info about cursors in this question


Post a Comment for "How To Retrieve All The Rows In My DB?"