我試圖填充動態創建的ListView
與從另一個函數獲取的ArrayList
。我收到錯誤"The constructor ArrayAdapter<String>(ShowRecords, ListView, ArrayList<String>) is undefined"
。這裏是我的ListActivity
代碼:使用ArrayList填充動態創建的ListView
public class ShowRecords extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
DatabaseHandler db = new DatabaseHandler(this);
ArrayList<String> records = db.getRecords();
ListView lv = new ListView(this);
this.setListAdapter(new ArrayAdapter<String>(this, lv, records));
}
}
這是我爲getRecords()
功能代碼:
public ArrayList<String> getRecords() {
ArrayList<String> recordList = new ArrayList<String>();
String selectQuery = "SELECT millis FROM records ORDER BY CAST(millis as SIGNED) DESC LIMIT 10";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
recordList.add(cursor.getString(0));
} while (cursor.moveToNext());
}
}
return recordList;
}
我該如何解決這個問題?
爲什麼從數據庫創建一個ArrayList,而不僅僅是使用simplecursoradapter? –
,因爲這是第一次以前曾經嘗試過這一點,我不完全確定我在做什麼 – scarhand
您可以使用[本頁]第12行下面的部分(http://thinkandroid.wordpress.com/2010/01/ 09/simplecursoradapters和 - 列表視圖/)。 –