我正在开发一个测验,其中在java类中我想在不使用startactivity的情况下单击下一个按钮后想要另一个类(问题),或者是否可以使用另一种方法调用另一个活动来传递另一个活动?请帮帮我们..非常感谢你们!我希望我的问题很清楚..我真的很感谢你的帮助!
的 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();
}
}
}
答案 0 :(得分:0)
尝试使用片段而不是活动,并且您不必为每个新片段使用start活动。要更改屏幕,您只需执行删除旧片段并添加新片段的事务。此机制也是比使用多个活动显示每个不同的问题更有效。