gpt4 book ai didi

android - 仅从android中的数据库获取最后一个值

转载 作者:行者123 更新时间:2023-11-30 01:35:34 26 4
gpt4 key购买 nike

<分区>

我已将值存储在数据库中,现在我正尝试从数据库中获取值。所有值都存储在数据库中,但是当我在字符串列表中获取值时,它只返回最后一个值。以下是我的代码。任何帮助将不胜感激。请

公共(public)列表 GetBigRun() {

List<Run_Data_Model> bigRun_list = new ArrayList<>();

this.open();
Cursor cursor = database.query(MySQLiteHelper.TABLE_NAME_BIG_RUN,
allColumns_table_big_run, null,
null, null, null, null);

cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Run_Data_Model mBigRunObj = new Run_Data_Model();
mBigRunObj.RunBtnState = cursor.getString(1);
mBigRunObj.RunImages = cursor.getString(2);
mBigRunObj.RunColor = cursor.getString(3);
mBigRunObj.RunDays = cursor.getString(4);
mBigRunObj.RunTime = cursor.getString(5);
bigRun_list.add(mBigRunObj);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
this.close();
return bigRun_list;

这是我创建的数据库。

     public static final String TABLE_NAME_BIG_RUN ="big_run";

public static final String BIG_RUN_COLUMN_ID = "_id";

public static String BIG_RUN_BTN_STATE ="btn_state";
public static String BIG_RUN_BTN_IMAGE ="btn_image";
public static String BIG_RUN_BTN_COLOR ="btn_color";
public static String BIG_RUN_DAYS ="days";
public static String BIG_RUN_TIME ="time";


//Query for create table
private static final String DATABASE_CREATE_TABLE_BIG_RUN = "create table "
+ TABLE_NAME_BIG_RUN + "("+ BIG_RUN_COLUMN_ID
+ " integer primary key autoincrement, " + BIG_RUN_BTN_STATE
+ " text , " + BIG_RUN_BTN_IMAGE
+ " text , " + BIG_RUN_BTN_COLOR
+ " text , " + BIG_RUN_DAYS
+ " text , " + BIG_RUN_TIME
+ " text );";

这里我在数据库中保存值。

     private void PutValues() {
mydata.DeleteAllBigRun();
/*if(mPref.GetRunCount().equals("0")) {*/

for (int i = 0; i < 73; i++) {
Run_Data_Model runModel = new Run_Data_Model();
runModel.RunDays = "Day " + (i + 12);
runModel.RunImages = String.valueOf(R.drawable.cross_icon);
runModel.RunBtnState = "0";
runModel.RunColor = "#e76025";


/* if (id == 1) {*/
sec = sec + 20;
int mins = sec / 60;
int remainder = sec - mins * 60;
int secs = remainder;
runModel.RunTime = mins + " min " + secs + " sec";


/* } else if (id == 2) {
sec = sec + 40;
int mins = sec / 60;
int remainder = sec - mins * 60;
int secs = remainder;
runModel.RunTime = mins + " min " + secs + " sec";
runModel.RunChallengeState = "2";

} else if (id == 3) {
runModel.RunTime = (i + 1) + " min ";
runModel.RunChallengeState = "3";
}*/
mydata.InsertBigRunInTable(runModel.RunBtnState, runModel.RunImages, runModel.RunColor, runModel.RunDays, runModel.RunTime);

}
mPref.SetRunCount("1");
//}


}

这就是我获取列表中的值并将其传递给适配器的方式。

       run_list = mydata.GetBigRun();
/* for(int i=0;i<run_list.size();i++) {
Log.d("run_list_size", run_list.get(i).RunDays);
}*/
gv = (GridView) findViewById(R.id.gridView1);
gv.setNumColumns(4);
RunChallengeAdapter adapter =new RunChallengeAdapter(this,run_list);
gv.setAdapter(adapter);
adapter.notifyDataSetChanged();

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com