0

我已经能够将数据传递给除此之外的其他活动。谁能看到我做错了什么。我得到的唯一错误是我的 TextView showmsg 没有出现在新活动中。有谁知道为什么?

 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);
4

2 回答 2

1

对于如何不显示您的文本,没有太多选择。

  1. 您的视图本身搞砸了:通过使用android:text="TEST"TextView showmsg 将一些示例文本放入 XML 文件中来检查这一点。您的文本应该出现,除非您的文本颜色或大小错误,或者上面碰巧有其他东西。

  2. 你实际上并没有找到它findViewById() (我希望你已经在调试器中仔细检查过)我同意你可能不想要的 alex R.id.showmsg。你的意思是放在R.id.resultTextView那里吗?

  3. 您传递的文本实际上并没有通过。您应该做一个日志语句,例如Log.v(TAG, "Passed text is " + in.getCharSequenceExtra("urs"));并确保文本实际上是通过的。

于 2013-04-22T14:22:01.223 回答
1

我没有测试它。但我认为这就是原因。

在这里改变:

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"));             
}
于 2013-04-22T15:09:52.530 回答