我想知道是否有办法做到这一点,这样看起来会更好。我该如何改变它,以便我可以比较整数,或者有更简单的方法来做到这一点,所以我没有很多 if 语句,或者我应该尝试使用枚举来比较字符串?
public void onClick(View v)
{
Intent choiceIntent = getIntent();
String msg = choiceIntent.getStringExtra("Choice1");
if (msg.contentEquals("Option1"))
{
if (v.getId() == R.id.button1)
{
Intent intent1 = new Intent(this,Choice3.class);
intent1.putExtra("Choice2", "Option3");
startActivityForResult(intent1, 1);
this.startActivity(intent1);
}
else if (v.getId() == R.id.button2)
{
Intent intent1 = new Intent(this,Choice3.class);
intent1.putExtra("Choice2", "Option4");
startActivityForResult(intent1, 1);
this.startActivity(intent1);
}
}
else if (msg.contentEquals("Option2"))
{
if (v.getId() == R.id.button1)
{
Intent intent1 = new Intent(this,Choice3.class);
intent1.putExtra("Choice2", "Option5");
startActivityForResult(intent1, 1);
this.startActivity(intent1);
}
else if (v.getId() == R.id.button2)
{
Intent intent1 = new Intent(this,Choice3.class);
intent1.putExtra("Choice2", "Option6");
startActivityForResult(intent1, 1);
this.startActivity(intent1);
}
}
}