[英]Add clicked item of a List view of a fragment to a List View of another fragment
[英]Database add item to list view?
我下载了此数据库脚本,我想知道如何将其转换为将项目添加到列表视图中。这是一个非常容易理解的数据库代码。
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.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.