0

im developing a quiz, wherein in java class i want to intent another class(question) after i clicked the next button without using the startactivity, or is it possible to call another activity using another method to pass another activity? please help me guys..thank you so much! i hope my question is clear..i really appreciate ur help!

Question1.java

public class Question1 extends Activity implements OnClickListener
{
int Scorecount = 0;
//private RadioGroup rgp;
private RadioButton rb1;
private RadioButton rb2;
private RadioButton rb3;
private Button b1;
//private TextView t1;
int currentQuestion = 0;
Toast t;



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

Scorecount = getIntent().getIntExtra("score",0);
rb1=(RadioButton)findViewById(R.id.option1);
rb2=(RadioButton)findViewById(R.id.option2);
rb3=(RadioButton)findViewById(R.id.option3);
b1=(Button)findViewById(R.id.selected);
b1.setOnClickListener(this);
//rgp=(RadioGroup)findViewById(R.id.QueGroup1);


//t1=(TextView)findViewById(R.id.txtdisplayanswer);
}

@Override
public void onClick(View v) {


    if(v == b1)

    {

        if(rb1.isChecked() || rb2.isChecked() || rb3.isChecked())
        {
            if(rb1.isChecked())
            {
                Scorecount++;
                Toast.makeText(getApplicationContext(),"Your answer is correct!",
                        Toast.LENGTH_LONG).show();

                /*LinearLayout layout = (LinearLayout) t.getView();
                layout.setGravity(Gravity.CENTER);
                layout.setBackgroundResource(R.drawable.toastgreen);
            //t1.setText("Your answer is correct!"  +rb1.getText());*/

            }
        /*
        if(rb2.isChecked() == true)
            //t1.setText("Your wrong, the correct answer is: "+rb1.getText());
        if(rb3.isChecked() == true)
            //t1.setText("Your wrong, the correct answer is: "+rb1.getText());*/

    else {
        // do nothing

        Toast.makeText(getApplicationContext(),"Your answer is wrong! The correct answers is:    " + rb1.getText(),
                Toast.LENGTH_LONG).show();

        /*LinearLayout layout = (LinearLayout) t.getView();
        layout.setGravity(Gravity.CENTER);
        layout.setBackgroundResource(R.drawable.toastred);*/

    }
            //Intent i = new Intent(this,Question2.class);
            Intent i= getIntent();
            i.putExtra("score", Scorecount);
            startActivity(i);
            finish();


        }

    }

}
4

1 回答 1

0

尝试使用片段而不是活动,并且您不必为每个新片段使用启动活动。要更改屏幕,您只需执行删除旧片段并添加新片段的事务。而且这种机制也更节省内存而不是使用多个活动来显示每个不同的问题。

于 2013-02-17T11:46:49.883 回答