【发布时间】:2017-08-15 07:12:09
【问题描述】:
我很难将保存在 SqlLite 数据库中的按钮单击存储的数据显示到 ListView 中。当我单击它以将数据添加到数据库时,它不会在按钮下方显示我想要的数据。
我的代码:
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();
}
这在模拟器中的样子:
我想要什么:
【问题讨论】:
标签: android sqlite listview arraylist android-sqlite