【发布时间】:2017-06-28 23:02:03
【问题描述】:
我有一个存储两个变量 Days 和 percent's 的表。我想将它们分配给特定的变量。从 Database Helper 类中,我得到了最后 7 个条目:
//----------------Graping the last seven elements ----------------------------------//
public ArrayList<StatsitcsHelper> GetWeaklyPrograss() {
SQLiteDatabase db = this.getReadableDatabase ();
Cursor cursor = db.rawQuery ("select * from " + TABLE_PROGGRES, null);
ArrayList<StatsitcsHelper> datas = new ArrayList<>();
if (cursor != null) {
cursor.moveToFirst ();
for (int i = cursor.getCount () - 7 ; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
StatsitcsHelper data = new StatsitcsHelper();
data.WeakleyDate= cursor.getString(cursor.getColumnIndex(COL_P_Date));
data.WeakleyPercent = cursor.getInt (cursor.getColumnIndex(COL_P_Percentage));
datas.add(data);
cursor.moveToNext ();
}
cursor.close ();
}
return datas;
}
我想构建 if 语句,如果天是星期六,然后将星期六百分比变量是统计类分配给与数据库关联的百分比。周日也是如此……等等。
在统计类内部:
public void WeaklyStatstics(){
int saturday = 0,
sunday = 0,
monday = 0,
tuesday = 0,
wednsday = 0,
thersday = 0,
friday = 0;
StatsitcsHelper statsitcsHelper = new StatsitcsHelper ();
DatabaseHelper databaseHelper = new DatabaseHelper (getActivity ());
//---------------------TO DO----------------------------------------//
}}
我不知道如何将数据库中列表中的每个项目分析到另一个类。
这是表格的插入:
// ----------------Proggres Table ------------------------------------//
public boolean insertPrograss(String Date, Integer percentage) {
SQLiteDatabase db = this.getWritableDatabase ();
ContentValues contentValues = new ContentValues ();
contentValues.put (COL_P_Date, Date);
contentValues.put (COL_P_Percentage, percentage);
long result = db.insert (TABLE_PROGGRES, null, contentValues);
db.close ();
return result != -1;
}
调度程序调用该方法,将使用日期格式将日期存储到当天,输出将是星期一,87。
我想编写一个方法来通过 GetWeaklyPrograss 方法获取最后 7 个输入。并将其分配给类似这样的变量
if(statsitcsHelper.WeakleyDate.equals ("monday")){
saturday = statsitcsHelper.WeakleyPercent;
}
这里是 statsitcsHelper:
public class StatsitcsHelper {
//-------------- Weakly Progress -----------------------/
public String WeakleyDate;
public int WeakleyPercent;
}
【问题讨论】:
-
问题不清楚,能否改写一下。
-
我有一个在 Statistics 类中可用的弱条形图,我正在尝试从数据库表中获取包含日期和百分比字段的变量。 if 语句将查看今天是哪一天并将百分比值分配给正确的变量以分配给图表
-
意思是,你有日期,你想把它改成工作日?
-
没有存储为天,所以很好去
-
那么你的问题是什么?我没明白。
标签: android android-sqlite android-arrayadapter android-cursor