无法将radiobutton添加到double上

时间:2014-04-14 00:22:02

标签: java android xml

该应用程序会经历几个问题,并在后台计算得分,以便在最后给出总体评分。出于某种原因,无论按下什么按钮,分数默认为4,我不认为它计算以下屏幕。

这是主要类的代码:

public class Main extends Activity 
{

    public static final String CALCULATION = "CALCULATION"; 
    public static double calculation;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main1);

        //RESTORES SAVED STATES
        if (savedInstanceState == null ){calculation = 0.0;}
        else{calculation = savedInstanceState.getDouble(CALCULATION);}

        RadioButton gpa1 = (RadioButton) findViewById(R.id.GPA1);
        RadioButton gpa2 = (RadioButton) findViewById(R.id.GPA2);
        RadioButton gpa3 = (RadioButton) findViewById(R.id.GPA3);
        RadioButton gpa4 = (RadioButton) findViewById(R.id.GPA4);       

        //Calculation based on GPA question
        if (gpa1.isChecked()){calculation = calculation + 1;}
        else{ if (gpa2.isChecked()) {calculation = calculation + 2; }
        else{ if (gpa3.isChecked()) {calculation = calculation + 3; }
        else{ if (gpa4.isChecked()) {calculation = calculation + 4; }
        else{calculation = 0.0; }}}}

        updateStandard ();

        //Get button to do button stuff like go to the next page
        Button butGPA = (Button) findViewById(R.id.butGPA);
        butGPA.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v) 
            {
                // TODO Auto-generated method stub
                Intent i = new Intent(Main.this, Main2.class);
                startActivity(i);
            }
        });


    }

    public void updateStandard() {
        // TODO Auto-generated method stub

    }

    //save value of calculation 
    @Override
    protected void onSaveInstanceState (Bundle outState)
    {
        super.onSaveInstanceState(outState);
        outState.getDouble(CALCULATION, calculation);
    }

}

以下是" next"之后的以下类的示例按下按钮:

public class Main2 extends Activity 
{

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);

        RadioButton hours1 = (RadioButton) findViewById(R.id.hours1);
        RadioButton hours2 = (RadioButton) findViewById(R.id.hours2);
        RadioButton hours3 = (RadioButton) findViewById(R.id.hours3);
        RadioButton hours4 = (RadioButton) findViewById(R.id.hours4);

        //Calculation based on ENROLLED question
        if (hours1.isChecked()){Main.calculation = Main.calculation + 1;}
        else{ if (hours2.isChecked())   {Main.calculation = Main.calculation + 2;   }
        else{ if (hours3.isChecked()) {Main.calculation = Main.calculation + 3; }
        else{ if (hours4.isChecked())   {Main.calculation = Main.calculation + 4;   }
        else{Main.calculation = 0.0;    }}}}

        updateStandard ();

        //Get button to do button stuff like go to the next page
        Button butHOURS = (Button) findViewById(R.id.butHOURS);
        butHOURS.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v) 
            {
                // TODO Auto-generated method stub
                Intent i = new Intent(Main2.this, Main3.class);
                startActivity(i);
            }
        });

    }

    public void updateStandard() {
        // TODO Auto-generated method stub

    }

}

在结果页面之前还有两个屏幕显示类似的设置。

0 个答案:

没有答案