使用 intent 发送 view 的 id,获取 “false” 提示

下面的类里的信息我想把它包含在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);

text.setText(id);这行有问题吧,int型的值不能直接赋给text.setText();正确的写法:text.setText(id+"");

findViewById(int id);
先理解一下这个方法,参数是int类型,android中的组件会转换成16进制存放与R文件中,查找的时候就通过相应的数值查找

针对你当前的问题,text.setText(id);如果里这里传int类型那个,源码中调用的方法为:
public final void setText(int resid) {
setText(getContext().getResources().getText(resid));
}
也就是说虚拟机会去查找当前resid所代表的值,很明显此时找不到
多看一下源码就能理解调用什么方法了