程序未显示更新数据

时间:2019-03-15 18:14:49

标签: java android sqlite

我有一个小问题:) 我尝试创建一个应用程序,以帮助用户开始在健身房锻炼。用户应该可以例如: -制定新计划 -编辑现有计划 -查看他所有的训练计划

要精确显示外观: 用户刚刚创建了一个新的培训计划,但是现在,他想对其进行编辑,因此他进入了正确的活动,然后应用询问他要编辑的日期(这涉及拆分-一种培训计划,用户可以在其中进行培训每天分为三个身体部位,有一天的冷却时间,例如星期一/星期三/星期五,用户点击星期一的TextView,因此更改应用布局,然后用户beeing询问他要编辑的确切位置(有ID列表)的计划,并由用户的身体部位指定),例如,我们有:

ID:1 第一身体部位:小腿 第二身体部位:腿 第三身体部位:胸部

用户希望将其编辑为3x Legs。

然后,应用程序正在更改布局,用户可以在其中选择选定的较早身体部位的运动。当用户选择感兴趣的锻炼时,他必须点击保存按钮。现在,用户希望查看修改后的计划,这有一个小问题。我不知道为什么,但是它在编辑之前显示了计划(小腿/小腿/胸部而不是我之前提到的小腿/小腿/大腿)

我没有收到任何错误,所以我不知道问题出在哪里。这就是为什么我决定向你们寻求帮助。

周一拆分表

private static final String SPLIT_MONDAY_BODY_PARTS_TABLE_NAME = "Monday_body_parts";
private static final String SPLIT_MONDAY_FIRST_BODY_PART = "First_body_part";
private static final String SPLIT_MONDAY_SECOND_BODY_PART = "Second_body_part";
private static final String SPLIT_MONDAY_THIRD_BODY_PART = "Third_body_part";

private static final String SPLIT_WEDNESDAY_BODY_PARTS_TABLE_NAME = "Wednesday_exercises";
private static final String SPLIT_WEDNESDAY_FIRST_BODY_PART = "First_body_part";
private static final String SPLIT_WEDNESDAY_SECOND_BODY_PART = "Second_body_part";
private static final String SPLIT_WEDNESDAY_THIRD_BODY_PART = "Third_body_part";

private static final String SPLIT_FRIDAY_BODY_PARTS_TABLE_NAME = "Friday_exercises";
private static final String SPLIT_FRIDAY_FIRST_BODY_PART = "First_body_part";
private static final String SPLIT_FRIDAY_SECOND_BODY_PART = "Second_body_part";
private static final String SPLIT_FRIDAY_THIRD_BODY_PART = "Third_body_part";

存储更新的身体部位的方法

public boolean updateSplitMondayBodyParts(String id, String firstBodyPart, String secondBodyPart, String thirdBodyPart) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put("id", id);
    values.put(SPLIT_MONDAY_FIRST_BODY_PART, firstBodyPart);
    values.put(SPLIT_MONDAY_SECOND_BODY_PART, secondBodyPart);
    values.put(SPLIT_MONDAY_THIRD_BODY_PART, thirdBodyPart);

    db.update(SPLIT_MONDAY_BODY_PARTS_TABLE_NAME, values, "ID = ?", new String[]{id});
    return true;
}

更新身体部位的方法

public void updateData() {
    updateTrainingPlan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            db.updateSplitMondayBodyParts(enterID.getText().toString(),firstBodyPartString,secondBodyPartString,thirdBodyPartString);
            Intent intent;
            intent = new Intent(getApplicationContext(), split_monday_update_exercises.class);
            intent.putExtra("ID",enterID.getText().toString());
            startActivity(intent);

        }
    });

将通过指定ID获取更新的身体部位的方法

public void getMondayBodyParts() {
    Cursor cursor = db.getMondaySplitPlanBodyPartsByID(TEST123);
    while (cursor.moveToNext()) {
        firstBodyPartString = cursor.getString(0);
        secondBodyPartString = cursor.getString(1);
        thirdBodyPartString = cursor.getString(2);
    }
}

应从数据库中调用另一个方法并在星期一拆分计划中更新数据的方法(仅练习)

public void updateData(Button button){

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String firstBP_FE_string, firstBP_SE_string, firstBP_TE_string, secondBP_FE_string, secondBP_SE_string, secondBP_TE_string, thirdBP_FE_string, thirdBP_SE_string, thirdBP_TE_string;

            firstBP_FE_string = firstBP_FE.getSelectedItem().toString();
            firstBP_SE_string = firstBP_SE.getSelectedItem().toString();
            firstBP_TE_string = firstBP_TE.getSelectedItem().toString();
            secondBP_FE_string = secondBP_FE.getSelectedItem().toString();
            secondBP_SE_string = secondBP_SE.getSelectedItem().toString();
            secondBP_TE_string = secondBP_TE.getSelectedItem().toString();
            thirdBP_FE_string = thirdBP_FE.getSelectedItem().toString();
            thirdBP_SE_string = thirdBP_SE.getSelectedItem().toString();
            thirdBP_TE_string = thirdBP_TE.getSelectedItem().toString();

            db.updateSplitMondayExercises(TEST123,firstBP_FE_string, firstBP_SE_string, firstBP_TE_string, secondBP_FE_string, secondBP_SE_string, secondBP_TE_string, thirdBP_FE_string, thirdBP_SE_string, thirdBP_TE_string);
        }
    });
}

* firstBP_FE,firstBP_SE等只是个微调器

这只是数据库中应该更新数据的一种方法

 public boolean updateSplitMondayExercises(String id, String firstBP_FE, String firstBP_SE, String firstBP_TE, String secondBP_FE, String secondBP_SE, String secondBP_TE, String thirdBP_FE, String thirdBP_SE, String thirdBP_TE) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put("ID", id);
    values.put(SPLIT_MONDAY_FIRST_BODY_PART_FIRST_EXERCISE, firstBP_FE);
    values.put(SPLIT_MONDAY_FIRST_BODY_PART_SECOND_EXERCISE, firstBP_SE);
    values.put(SPLIT_MONDAY_FIRST_BODY_PART_THIRD_EXERCISE, firstBP_TE);

    values.put(SPLIT_MONDAY_SECOND_BODY_PART_FIRST_EXERCISE, secondBP_FE);
    values.put(SPLIT_MONDAY_SECOND_BODY_PART_SECOND_EXERCISE, secondBP_SE);
    values.put(SPLIT_MONDAY_SECOND_BODY_PART_THIRD_EXERCISE, secondBP_TE);

    values.put(SPLIT_MONDAY_THIRD_BODY_PART_FIRST_EXERCISE, thirdBP_FE);
    values.put(SPLIT_MONDAY_THIRD_BODY_PART_SECOND_EXERCISE, thirdBP_SE);
    values.put(SPLIT_MONDAY_THIRD_BODY_PART_THIRD_EXERCISE, thirdBP_TE);

    db.update(SPLIT_MONDAY_PLAN, values, "ID = ?", new String[]{id});
    return true;
}

显示用户培训计划(整周)的方法

public void getSplit(TextView textView) {

    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            StringBuffer buffer = new StringBuffer();
            Cursor cursor = db.getSplitAllPlans();
            if (cursor.getCount() == -1) {
                setMessage("Error", "There's no data inside!");
                return;
            }
            while (cursor.moveToNext()) {
                buffer.append("First body part: " + cursor.getString(1) + "\n");
                buffer.append("First exercise: " + cursor.getString(2) + "\n");
                buffer.append("Second exercise: " + cursor.getString(3) + "\n");
                buffer.append("Third exercise: " + cursor.getString(4) + "\n\n");
                buffer.append("Second body part: " + cursor.getString(5) + "\n");
                buffer.append("First exercise: " + cursor.getString(6) + "\n");
                buffer.append("Second exercise: " + cursor.getString(7) + "\n");
                buffer.append("Third exercise: " + cursor.getString(8) + "\n\n");
                buffer.append("Third body part: " + cursor.getString(9) + "\n");
                buffer.append("First exercise: " + cursor.getString(10) + "\n");
                buffer.append("Second exercise: " + cursor.getString(11) + "\n");
                buffer.append("Third exercise: " + cursor.getString(12) + "\n\n\n\n");
            }
            setMessage("Data", buffer.toString());
        }
    });
}

上述代码中调用的方法,它必须从数据库中获取所有拆分计划

public Cursor getSplitAllPlans() {
    SQLiteDatabase db = this.getReadableDatabase();
    String query = "SELECT * FROM " + SPLIT_MONDAY_PLAN + " UNION ALL SELECT * FROM " + SPLIT_WEDNESDAY_PLAN + " UNION ALL SELECT * FROM " + SPLIT_FRIDAY_PLAN;
    Cursor cursor = db.rawQuery(query, null);
    return cursor;

我希望我不会错过肛门痛。

0 个答案:

没有答案