Q:

Only last row of sqlite database is being displayed

This is my sqlite database code 
public void onCreate(SQLiteDatabase db) {
        String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_USER + "("
                + KEY_ID + " INTEGER PRIMARY KEY,"+ SERVER_ID + " TEXT,"+ ACCESS_TOKEN + " TEXT," + FIRST_NAME
                + " TEXT," + LAST_NAME + " TEXT," + USER_EMAIL + " TEXT,"
                + USERNAME + " TEXT," + ADDRESS + " TEXT," + LATITUDE + " TEXT,"
                + LONGITUDE + " TEXT," + BLOOD_GROUP + "  TEXT," + GENDER + " TEXT,"
                + PHONE_NUMBER + " TEXT," + MOBILE_NUMBER + " TEXT," + DOB_YEAR + " TEXT,"
                + DOB_MONTH + " TEXT," + DOB_DAY + " TEXT," + COUNTRY + " TEXT," + IMAGE_URL
                + "  TEXT," + TYPE + " TEXT" +");";
        db.execSQL(CREATE_LOGIN_TABLE);

and this is my code to get all the values from the table
 public HashMap<String, String> getBPositiveData(){
        HashMap<String, String> getData = new HashMap<>();
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery("select * from user where type =? and blood_group =?", new String[]{"friends", "B_plus"});
        //Move to first
       if (cursor.moveToFirst()){

           do {
                   getData.put("server_id", cursor.getString(1));
                   getData.put("first_name", cursor.getString(3));
                   getData.put("last_name", cursor.getString(4));
                   getData.put("blood_group", cursor.getString(10));
                   getData.put("mobile_number", cursor.getString(13));
                   getData.put("imageURL", cursor.getString(18));
                   cursor.moveToNext();
               int abc = cursor.getCount();
               Log.e("cursorCount", String.valueOf(abc));
           }while (!cursor.isAfterLast());
           cursor.close();
        }
        return getData;
    }

In my database all the rows are properly inserted and the query provides me with the required data as well (I checked the database from genymotion emulator so I am sure that the data are present there). My problem is that i only get the value form the last row of that table. Could anyone please tell me what is it that I'm doing wrong here?? the code I use to retrieve the values in my activity is this: 
HashMap<String, String> profile = db.getBPositiveData();
                final String fname = profile.get("first_name");
                final String lname = profile.get("last_name");
                final String bgroup = profile.get("blood_group");
                final String mnumber = profile.get("mobile_number");
                final String iurl = profile.get("imageURL");

Thank You in advance. 

A:

Create a new class User  
public class User {
String first_name;
String last_name;
String blood_group;
// ...the rest of the propertied
}  

Change HashMap declaration for getData  
HashMap userList = new HashMap<>();  
Then mack a change in your code  
User currentUser = null;
if(cursor.moveToFirst())
{

    do {
        currentUser = new User();
        currentUser.first_name = cursor.getString(3);
        currentUser.last_name = cursor.getString(4);
        currentUser.blood_group = cursor.getString(10);
        // the rest of your data for user
        String rowKey = cursor.getString(cursor.getColumnIndexOrThrow("_id"));
        userList.put(rowKey, currentUser);
        cursor.moveToNext();

        // the rest of your code

    } while (!cursor.isAfterLast());
    cursor.close();
    return userList;
}  

Then change the return type of your method accordingly from HashMap into HashMap.
Let me know if this works for you

