Image 如何更改按钮的图像
我这里的问题是如何在单击按钮后为其显示新图像,但条件来自另一个类。我是这里的新手,我想知道如何将这个类与其他类连接起来。我试过这个意图 这是我的密码 这是我们的问题课Image 如何更改按钮的图像,image,class,button,android-intent,Image,Class,Button,Android Intent,我这里的问题是如何在单击按钮后为其显示新图像,但条件来自另一个类。我是这里的新手,我想知道如何将这个类与其他类连接起来。我试过这个意图 这是我的密码 这是我们的问题课 @Override // TODO Auto-generated method stub public void onClick(View v) { String answer = "Marianas Trench"; String answer2 = "marianas trench"; String a
@Override
// TODO Auto-generated method stub
public void onClick(View v) {
String answer = "Marianas Trench";
String answer2 = "marianas trench";
String answer3 = "MARIANAS TRENCH";
String check = input.getText().toString();
if (check.contentEquals(answer)){
tvresult.setText("Correct");
Intent myIntent= new Intent("com.turtleexploration.LEVEL1");
startActivity(myIntent);
}else if (check.contentEquals(answer2)){
tvresult.setText("Correct");
Intent myIntent= new Intent("com.turtleexploration.LEVEL1");
startActivity(myIntent);
}else if (check.contentEquals(answer3)){
tvresult.setText("Correct");
Intent myIntent = new Intent("com.turtleexploration.LEVEL1");
startActivity(myIntent);
}else{
tvresult.setText("Wrong");
}
Intent intObj = new Intent(Question.this, Level1.class);
intObj.putExtra("ANSWER", answer);
startActivity(intObj);
}
这是问题选择课
ImageButton l1 = (ImageButton) findViewById(R.id.l1);
TextView t1 = (TextView) findViewById(R.id.t1);
Intent intename = getIntent();
String mainans = "Marianas Trench";
String ans = (String) intename.getSerializableExtra("ANSWER");
if (ans == mainans){
l1.getBackground().equals(getResources().getDrawable(R.drawable.m1));
t1.setText("Correct");
}else{
}
按钮位于问题选择菜单中…似乎您没有使用携带数据的捆绑包。意图只调用下一个活动。包必须包括在内 比如: 在下一节课上。使用此选项可获得传递的数据:
Bundle b = new Bundle();
b = getIntent().getExtras();
String Gotanswer = b.getString("ANSWER");
并使用字符串Gotanswer
来使用它
但还有一件事,如果您想将字符串答案传递给下一个类,在这段代码中是不可能的,因为在您的每个条件中,都有一行开始下一个类,例如:
Intent myIntent = new Intent("com.turtleexploration.LEVEL1");
startActivity(myIntent);
这样做将启动下一个类,而无需通过下面的intObj
代码。
如果我没弄错的话,这是事实
另外,与其使用If-Else-If
,不如使用开关
当你看到这个答案时,进一步解释你的问题
Kaya yan pre! haha
在这个问题上。。我的工作似乎一切都很好。。但我无法连接到一个意图。我不知道为什么..Bundle b=新Bundle();b、 putString(“应答”,应答);intObj的意图=新的意图(问题.this,级别1.class);b.putExtras(b);星触觉(intObj);哦,对不起。“b.putExtra(b)”应为“intObj.putExtra(b)”
Kaya yan pre! haha