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

私はそれをテストしていません。しかし、それが理由だと思います。

ここで変更:

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 に答える
1

テキストを非表示にするオプションはそれほど多くありません。

  1. ビュー自体がおかしくなっています: android:text="TEST"TextView の showmsg を使用して XML ファイルにサンプル テキストを入れて、これを確認してください。テキストの色やサイズが間違っている場合や、その上に何か他のものがあった場合を除き、テキストが表示されるはずです。

  2. あなたは実際にはそれを見つけていませんfindViewById() (デバッガーでそれを再確認したことを願っています)私はあなたが望まないかもしれないというアレックスに同意しますR.id.showmsg. R.id.resultTextView代わりに置くつもりだったの?

  3. 渡されたテキストは実際には通過していません。のようにログステートメントを実行Log.v(TAG, "Passed text is " + in.getCharSequenceExtra("urs"));し、テキストが実際に送信されていることを確認する必要があります。

于 2013-04-22T14:22:01.223 に答える