下面的类里的信息我想把它包含在intent里面发送给一个activity。当图片按钮“superman”按下的时候,onClick()方法会发送intent给SuperheroActivity。但是当我试着在另一个activity里面检索信息的时候,得到了“false”
public class MenuActivity extends Activity implements
OnClickListener {
private ImageButton superman;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
superman = (ImageButton) findViewById(R.id.superman);
superman.setOnClickListener(this);
}
@Override
public void onClick(View v) {
Intent intent = new Intent(MenuActivity.this, SuperheroActivity.class);
intent.putExtra("id", v.getId());
startActivity(intent);
}
}
SuperheroActivity:
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);