我想传递数据到其它的activities除了现在这个。谁能告诉我问题出现在哪里。我现在获得的唯一的错误是TextView showmsg不能在新的activity中显示。这是为什么啊?
public class MyScanActivity extends Activity
{
private static final String MY_CARDIO_APP_TOKEN = "NOT THE PROBLEM";
final String TAG = getClass().getName();
private Button scanButton;
private TextView resultTextView;
private Button buttonBack;
private TextView showmsg;
private int MY_SCAN_REQUEST_CODE = 100; // arbitrary int
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.myscan);
Intent in = getIntent();
if (in.getCharSequenceExtra("usr") != null) {
final TextView setmsg = (TextView)findViewById(R.id.showmsg);
setmsg.setText(in.getCharSequenceExtra("usr"));
}
resultTextView = (TextView)findViewById(R.id.resultTextView);
scanButton = (Button)findViewById(R.id.scanButton);
buttonBack = (Button)findViewById(R.id.buttonBack);
showmsg = (TextView) findViewById(R.id.showmsg);
1.在 TextView showmsg 中使用 android:text="TEST",然后在 xml 文件输入一些简单的 text 来检查 view。
2. 在 debugger 中你可以使用 findViewById() 再次检查。
3. 你传递的 text 没有显示出来,你应该创建一个日志语句,比如: Log.v(TAG, "Passed text is " + in.getCharSequenceExtra("urs"));
看下 in.getCharSequenceExtra("usr") 这个有没有值,没有的话就得检查下你上一个Activity传递值的代码怎么写的啦