Android 正在尝试发送视图';他有一个意图。获得;假;

Android 正在尝试发送视图';他有一个意图。获得;假;,android,Android,这个类包含我想要发送给另一个活动的信息。当按下图像按钮“超人”时,onClick()处理程序会向超级英雄活动发送一个意图。但当我尝试在其他活动中检索该信息时,我得到了“false” } 这是一段试图从意图中检索信息的代码。注意:这是超级英雄活动 Intent intent = getIntent(); id = intent.getIntExtra("id", 0); // This is just a dirty way for me to see the value of the id I

这个类包含我想要发送给另一个活动的信息。当按下图像按钮“超人”时,onClick()处理程序会向超级英雄活动发送一个意图。但当我尝试在其他活动中检索该信息时,我得到了“false”

}

这是一段试图从意图中检索信息的代码。注意:这是超级英雄活动

Intent intent = getIntent();
id = intent.getIntExtra("id", 0);
// This is just a dirty way for me to see the value of the id I am getting.
TextView text = (TextView) findViewById(R.id.superheroText); 
text.setText(id);
使用
getExtras()

Intent intent = getIntent();
id = intent.getExtras().getInt("id");

记住你不能
setText(int)
int
必须是
字符串

所以改变

TextView text = (TextView) findViewById(R.id.superheroText); 
text.setText(id);


使用id=intent..getExtras().getInt(“id”)从intent获取数据…

错误就在这行代码中

text.setText(id);
表示资源id(即
String
资源id)。 试着更换和使用这个

text.setText(String.valueOf(id));
超高温

Bundle extras = getIntent().getExtras();
id = extras.getInt("id");
TextView text = (TextView) findViewById(R.id.superheroText); 
text.setText(id+"");

重载setText方法以获取字符串资源id作为参数。重载setText方法以获取字符串资源id作为参数。
text.setText(String.valueOf(id));
Bundle extras = getIntent().getExtras();
id = extras.getInt("id");
TextView text = (TextView) findViewById(R.id.superheroText); 
text.setText(id+"");