I am having difficulty displaying data stored by button clicks that are saved in an SqlLite database into a ListView. It doesn't show the data as i want underneath the button when i click it to add the data to the database.
My code:
boolean hasMoreData = cursor.moveToFirst();
while (hasMoreData) {
// get the value out of each column
long key = cursor.getLong(cursor.getColumnIndexOrThrow(MyDataEntry._ID));
String studentID = cursor.getString(cursor.getColumnIndexOrThrow(MyDataEntry.STUDENT_ID_COLUMN));
String studentGrade = cursor.getString(cursor.getColumnIndexOrThrow(MyDataEntry.STUDENT_GRADE_COLUMN));
//For now, just print out the record to the log.
ArrayList<String> myList = new ArrayList<>();
myList.add( " student id: "+ studentID);
myList.add(" student grade : " +studentGrade);
ArrayAdapter<String> myAdapter =
new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,myList);
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(myAdapter);
System.out.println("RECORD KEY: " + key + " student id: " + studentID + " student grade : " + studentGrade);
//move on to the next row!
hasMoreData = cursor.moveToNext();
}
what this looks like in emulator :
What I want: