更新:問題修復 - ActionBar覆蓋列表中的第一個項目。ListView不顯示第一行值
SOLUTION:Android AppBarLayout overlaps listview
在我的計劃,我從數據庫中檢索數據,並使用列表視圖顯示它。 但是,第一行元素總是在進程中跳過,顯示從第二行開始。
public void displaydata(){
Cursor res = myDb.getAllData();
lv = (ListView) findViewById(R.id.idListView);
if(res.getCount() == 0){
//show message
return;
}
ArrayList<String> buffer = new ArrayList<>();
while(res.moveToNext()){
buffer.add(res.getString(1));
};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,buffer);
lv.setAdapter(adapter);
}
如何從第一行顯示? 任何幫助表示讚賞,謝謝。
編輯:我試過所有建議使用'做'和'for循環'的答案,所有這些都給出了相同的結果。
我相信它是因爲'res.moveToNext()'所以索引0被跳過轉到下一行 – Derek
相關:http://stackoverflow.com/questions/10723770/whats-the-best-way- to-iterate-an-android-cursor – JBC
[重複Android遊標的最佳方式是什麼?](http://stackoverflow.com/questions/10723770/whats-the-best-way-to-iterate- an-android-cursor) –