I have created a database which stores group details.I want to show that group details in a listview.But when i open my app i only see the the last values in the database.why this is happening???
Getting Value from database
public ArrayList<GroupModel> getAllGroups() {
SQLiteDatabase database = getWritableDatabase();
String query = "Select * From " + tableName;
GroupModel groupModel;
Cursor c = database.rawQuery(query, null);
while (c.moveToNext()) {
getGroupInfo = new ArrayList<GroupModel>();
groupModel = new GroupModel(c.getString(c.getColumnIndexOrThrow(groupName)), c.getString(c.getColumnIndexOrThrow(createdOn)));
getGroupInfo.add(groupModel);
}
return getGroupInfo;
}
When i debugged my
1st iteration List value[0]="A","B"
2nd iteration List value[0]="p","q";
why this is happeninng, the desired outcome should be
1st iteration List value[0]="A","B"
2nd iteration List value[1]="p","q";
Model Class
public class GroupModel {
private String groupId, groupName, groupCreatedDate, contactId, contactName, contactNumber;
public GroupModel() {
}
public GroupModel(String groupName, String groupCreatedDate) {
this.groupName = groupName;
this.groupCreatedDate = groupCreatedDate;
}
public GroupModel(String groupId, String contactId, String contactName, String contactNumber) {
this.groupId = groupId;
this.contactId = contactId;
this.contactName = contactName;
this.contactNumber = contactNumber;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getGroupCreatedDate() {
return groupCreatedDate;
}
public void setGroupCreatedDate(String groupCreatedDate) {
this.groupCreatedDate = groupCreatedDate;
}
public String getContactId() {
return contactId;
}
public void setContactId(String contactId) {
this.contactId = contactId;
}
public String getContactName() {
return contactName;
}
public void setContactName(String contactName) {
this.contactName = contactName;
}
public String getContactNumber() {
return contactNumber;
}
public void setContactNumber(String contactNumber) {
this.contactNumber = contactNumber;
}
}