/*I have problem with intent that i can't settext which i have got from getIntent from previous activity*/
public class Done extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_done);
TextView text = (TextView)findViewById(R.id.donetxt);
int tappedapples=0;
RelativeLayout rl = (RelativeLayout)findViewById(R.id.RelativeLayout);
rl.setBackgroundResource(R.drawable.background);
/*I want to setText which i have got from previous activity*/
Bundle extras = getIntent().getExtras();
if(extras!=null){
int apples = extras.getInt("tappedapples",0);
text.setText(Integer.parseInt("tappedapples"));
}
}
}
/ 我的意图有问题,我无法设置我从之前的活动中获取getIntent的文本 /
答案 0 :(得分:1)
改变这个:
int apples = extras.getInt("tappedapples",0);
text.setText(Integer.parseInt("tappedapples"));
要:
int apples = extras.getInt("tappedapples",0);
text.setText(apples+"");