TextView没有出现在其他活动
问题描述:
我已经能够将数据传递给除此之外的其他活动。任何人都可以看到我做错了什么。我得到的唯一错误是我的TextView showmsg没有显示在新的活动中。有谁知道为什么?TextView没有出现在其他活动
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);
答
对于如何显示文本没有太多的选择。
你自己搞砸的观点:通过将一些示例文本中的TextView showmsg使用
android:text="TEST"
在XML文件中进行检查。你的文字应该出现,除非你的文字是错误的颜色或大小,或者其他的东西恰好在它之上。你实际上没有找到它
findViewById()
(我希望你已经在调试器中检查过)我同意亚历克斯,你可能不想要R.id.showmsg
。你的意思是把R.id.resultTextView
放在那里吗?您的传递文本实际上并未通过。你应该做一个日志声明,如
Log.v(TAG, "Passed text is " + in.getCharSequenceExtra("urs"));
,并确保文本实际上是通过。
答
我还没有测试过。但我认为这是原因。
变化在这里:
if (in.getCharSequenceExtra("usr") != null) {
final TextView setmsg = (TextView)findViewById(R.id.showmsg);
setmsg.setText(in.getCharSequenceExtra("usr"));
}
与此:
showmsg = (TextView) findViewById(R.id.showmsg);
if (in.getCharSequenceExtra("usr") != null) {
showmsg.setText(in.getCharSequenceExtra("usr"));
}
你在showmsg显示? – surender8388 2013-04-20 16:14:27
你是故意将setmsg设置为R.id.showmsg吗? – alex 2013-04-20 16:18:47