我有一个存储主题的数据库。我想在微调器中显示所有主题。我可以进入第一个主题,但不能进入其他三个。
虽然所有三个日志:
topicCursor: android.database.sqlite.SQLiteCursor@429ba4a8
str: test0
labels: [test0]
dataAdapter: android.widget.ArrayAdapter@429bad58
spinner: android.support.v7.widget.AppCompatSpinner{4296ed00 VFED..C. ......I. 0,0-0,0 #7f0d0055 app:id/spinner}
topicCursor do: android.database.sqlite.SQLiteCursor@429ba4a8
str: test
labels: [test]
dataAdapter: android.widget.ArrayAdapter@429bb6f0
spinner: android.support.v7.widget.AppCompatSpinner{4296ed00 VFED..C. ......I. 0,0-0,0 #7f0d0055 app:id/spinner}
topicCursor do: android.database.sqlite.SQLiteCursor@429ba4a8
str: Testing
labels: [Testing]
dataAdapter: android.widget.ArrayAdapter@429bbed8
spinner: android.support.v7.widget.AppCompatSpinner{4296ed00 VFED..C. ......I. 0,0-0,0 #7f0d0055 app:id/spinner}
topicCursor do: android.database.sqlite.SQLiteCursor@429ba4a8
public void loadSpinnerData() {
// database handler
DatabaseHelper db = DatabaseHelper.getInstance(getApplicationContext());
Cursor topicCursor = db.getAllTopics();
Log.v("topicCursor", topicCursor.toString());
db.close();
String str;
if (topicCursor.moveToFirst()) {
do {
str = topicCursor.getString(topicCursor.getColumnIndex("topic_name"));
Log.v("str", str);
ArrayList<String> labels = new ArrayList<String>();
labels.add(str);
Log.v("labels", labels.toString());
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, labels);
Log.v("dataAdapter", dataAdapter.toString());
//Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
//Attaching data adapter to spinner
spinner.setAdapter(dataAdapter);
Log.v("spinner", spinner.toString());
Log.v("topicCursor do", topicCursor.toString());
} while (topicCursor.moveToNext());
}
}
我不知道我在这里缺少什么,比如为什么微调器中只显示最后一个列表项?有什么建议么?