我下载了这个数据库脚本,我想知道如何将其转换为将项目添加到列表视图中...这是一个非常容易理解的数据库代码..
http://www.anotherandroidblog.com/wp-content/uploads/2010/08/AABDatabase.zip
这是它的来源..
我也猜测它可能在这里?
/**
* retrieves a row from the database with the id number in the corresponding
* user entry field
*/
private void retrieveRow()
{
try
{
// The ArrayList that holds the row data
ArrayList<Object> row;
// ask the database manager to retrieve the row with the given rowID
row = db.getRowAsArray(Long.parseLong(updateIDField.getText().toString()));
// update the form fields to hold the retrieved data
updateTextFieldOne.setText((String)row.get(1));
updateTextFieldTwo.setText((String)row.get(2));
}
catch (Exception e)
{
Log.e("Retrieve Error", e.toString());
e.printStackTrace();
}
}
答案 0 :(得分:1)
要将数据库中的项目添加到ListView,您可以拥有一个ArrayList
1。)ArrayList<String> arrList = new ArrayList<String>();
2.。)从数据库中获取项目并将它们添加到ArrayList
if(c.getCount() > 0){
c.moveToFirst();
for (int i = 0; i < c.getCount() - 1; i++) {
arrList.add(c.getString(0));
c.moveToNext();
}
3。)Then populate the Adapter with the ArrayList(arrList).
4。)And fill the ListView with the Adapter.