我有一个应用程序,其中许多活动打开另一个,其中一些东西是在打开它的按钮之后设置的(图像、标签等)。在这个活动关闭后,我想返回一个字符串 vith 值“1”,它将转换为 int 并用于设置分数。
在返回的活动中,我有这个:
Intent i;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.vie);
img = (ImageView) findViewById(R.id.img);
et = (EditText) findViewById(R.id.et);
btn = (Button) findViewById(R.id.btnCheck);
txt = (TextView) findViewById(R.id.txt);
win_sound = MediaPlayer.create(Vie.this, R.raw.win);
wrong_sound= MediaPlayer.create(Vie.this, R.raw.wrong);
i = getIntent();
Bitmap back = i.getParcelableExtra("back");
Drawable b = new BitmapDrawable(getResources(), back);
img.setImageDrawable(b);
String tag = i.getStringExtra("tag");
Object tag2 = (Object) tag;
img.setTag(tag2);
btn.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
boolean mb = check(et, img);
if (mb) {
// Sunet toast thread
txt.setText(title(img));
win_sound.start();
i.putExtra("score", "1");
setResult(RESULT_OK, i);
Thread t = new Thread() {
@Override
public void run() {
// TODO Auto-generated method stub
super.run();
try {
sleep(win_sound.getDuration());
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
} finally {
finish();
}
}
};
t.start();
}
if (!mb) {
// sunet toast thread
wrong_sound.start();
Toast t = Toast.makeText(getApplicationContext(),"Wrong answer! Please check if you have spelled corectly the name of the team!",Toast.LENGTH_LONG);
t.show();
}
}
和 OnActivityResult 方法:
int a = 0
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (data.getExtras().containsKey("score")) {
a +=Integer.valueOf(data.getStringExtra("score"));
}
}
并且 textView 设置为显示:
txtScore.setText(a);
但这给了我一个错误,这是我的 LogCat:
06-29 15:28:25.312: E/AndroidRuntime(981): Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x0
06-29 15:28:25.312: E/AndroidRuntime(981): at android.content.res.Resources.getText(Resources.java:230)
06-29 15:28:25.312: E/AndroidRuntime(981): at android.widget.TextView.setText(TextView.java:3769)
06-29 15:28:25.312: E/AndroidRuntime(981): at com.RandDdev.uclquiz.Teams.onCreate(Teams.java:61)
你可以帮帮我吗?