我下载了这个数据库脚本,我想知道如何将其转换为将项目添加到 ListView 中..它是一个非常容易理解的数据库代码..
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();
}
}
最佳答案
要将数据库中的项目添加到 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.
关于java - 数据库添加项目到 ListView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7550808/