1

I have created the bases for an Android app that asks a user a set of questions; linked to diabetes symptoms,and produces a diabetic status based on the user's answers. However I am having trouble with creating a point system to produce the diabetic states.

The app asks 11 questions (on separate activities) that only 7 are relevant to diabetic symptoms. Each question's answers are within a RadioGroup and I have managed to produce a toast to show which has been selected (my own testing use). I would like to give each RadioButton (answer) a number value so that for instance if a user scores above 10 then they are diabetic. Can anyone help??

RadioGroup sample code within one of the activity's .java file:

final RadioGroup radioDQ1Group = (RadioGroup) findViewById(R.id.radioDQ1Group1);
    Button btnNext = (Button) findViewById(R.id.btnNext1);
    btnNext.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(Diabetes_Question_1.this, Diabetes_Question_3.class));

            // get selected radio button from radioGroup
            int selectedId = radioDQ1Group.getCheckedRadioButtonId();

            // find the radio button by returned id
            RadioButton radioDQ1Button = (RadioButton) findViewById(selectedId);

            Toast.makeText(Diabetes_Question_1.this, radioDQ1Button.getText(), Toast.LENGTH_SHORT).show();
}
    });

I would like each activity's score to be sent to the next activity or saved globally within the app so that once a 'Calculate' button is pressed the app will total the score and show the user another activity stating their potential diabetic states. Can anyone help ASAP as my deadline is tight?? Any help will be greatly appreciated!!

4

1 回答 1

1

一种选择是将分数保存在 SharedPreferences 变量中。当您计算时,您可以从中读取。

http://developer.android.com/reference/android/content/SharedPreferences.html

选项 2:

我猜在每个活动中,您都在单击按钮时调用 nextActivity,因此在 startNextActivity 的意图中,您可以传递分数。

于 2013-03-19T16:46:11.013 回答