Java Android使用arraylist显示数据库中的信息
在我设计的arraylist中,我不知道如何获得我设法获得的信息,以便添加并保存到我的数据库中。此按钮用于获取记录。我已将日志跟踪用于检查此项,但我无法将其传输到列表视图。。。。我对安卓相当陌生Java Android使用arraylist显示数据库中的信息,java,android,arraylist,Java,Android,Arraylist,在我设计的arraylist中,我不知道如何获得我设法获得的信息,以便添加并保存到我的数据库中。此按钮用于获取记录。我已将日志跟踪用于检查此项,但我无法将其传输到列表视图。。。。我对安卓相当陌生 public class ActualSalesTracker extends Activity implements OnClickListener { Button BtnSalesCal, BtnAddRecordDB, BtnViewRecordsDB; EditText it
public class ActualSalesTracker extends Activity implements OnClickListener {
Button BtnSalesCal, BtnAddRecordDB, BtnViewRecordsDB;
EditText item_name, item_cost, item_price_value, item_postage, actual_pl;
SalesProfitLossCal actSalesCal = new SalesProfitLossCal();
Cursor c;
DbAdapter db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actual_sales_tracker);
db = new DbAdapter(this);
Log.d("write database", "got here");
Button salesCalBtn = (Button) findViewById(R.id.BtnSalesCal);
// register the click event with the sales calculating profit/loss
// button
salesCalBtn.setOnClickListener(new OnClickListener() {
// activate the view record button
Button viewRecordsDB = (Button) findViewById(R.id.BtnViewRecordsDB);
// register the click event with the add record button
viewRecordsDB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
db.open();
c = db.getAllRecords();
db.close();
Log.d("got records", "Got the records");
Toast.makeText(ActualSalesTracker.this, "Loading saved sales",
Toast.LENGTH_SHORT).show();
}
});
}
}
}
从数据库适配器获取所有记录文件
public Cursor getAllRecords() {
return db.query(DATABASE_TABLE, new String[] { KEY_ROWID,
KEY_ITEM_NAME, KEY_ITEM_COST, KEY_ITEM_PRICE_VALUE,
KEY_ITEM_POSTAGE, KEY_ACTUAL_PL }, null, null, null, null,
null, null);
}
/**
* method to retrieve a particular record
*/
public Cursor getRecord(long id) throws SQLException {
Cursor mCursor = db.query(true, DATABASE_TABLE, new String[] {
KEY_ROWID, KEY_ITEM_NAME, KEY_ITEM_COST, KEY_ITEM_PRICE_VALUE,
KEY_ITEM_POSTAGE, KEY_ACTUAL_PL }, KEY_ROWID + "=" + id, null,
null, null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
ArrayList文件列表=新建ArrayList Cursor Cursor=database.rawQuerySELECT*FROM+您的表名+其中+您的条件+\,null
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
<the type you want to get the result> offlineFile = cursorToOfflineFile(cursor);
fileList.add(offlineFile);
cursor.moveToNext();
}
光标。关闭
返回文件列表 发布db.getAllRecords的代码;请从问题中删除不相关的代码。只发布足以识别您的问题的代码,否则大多数人甚至不会阅读问题。可以!感谢您的反馈-我是新手,非常感谢您为我研究这个问题。为什么在查询数据库时使用ArrayList?查询返回一个游标,该游标可与SimpleCursorAdapter一起用于填充ListView。如果你搜索的话,有很多例子。