0

私はアンドロイドを学んでいるので、ボタンで新しいアクティビティを開始し、前のアクティビティの編集テキストでユーザーが入力したテキストは、新しく開始されたアクティビティのテキストビューに表示する必要があるプログラムで練習していましたが、ユーザー入力を新しいアクティビティに渡すと、何も表示されません。ここで問題になる可能性があるのはコードです: この親アクティビティを考えてみましょう:

        case R.id.Sfr:
        Intent data= new Intent(SendData.this, RecieveData.class);
        Bundle check = new Bundle();

        check.putString("UmerData", cheese);
        medt.setText(cheese);
        data.putExtras(check);
        startActivityForResult(data, 5); // It is used to return data from child activity
        break;

渡されたユーザー入力を表示する子アクティビティは次のとおりです。

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recievedata);
    Initialize(); 
    Bundle got = getIntent().getExtras();

    rt1.setText(got.getString("UmerData"));

}

この子アクティビティに渡されたユーザー入力が表示されないのはなぜですか?

4

3 に答える 3

1

これを試して -

case R.id.Sfr:
    Intent data= new Intent(SendData.this, RecieveData.class);
    Bundle check = new Bundle();
    check.putString("UmerData", cheese);
    medt.setText(cheese);
    data.putExtras(check);
    startActivity(data);
    break;

渡されたユーザー入力を表示する子アクティビティは次のとおりです。

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.recievedata);
    InitializeFuck();
    Bundle got = getIntent().getExtras();
    rt1.setText(got.getString("UmerData"));
}

これらの既存の回答を見てください-

  1. アクティビティ間でデータを渡す

  2. アクティビティ間でデータを渡す方法

于 2012-08-11T12:17:43.807 に答える
1

最初のアクティビティに書き込みます:-

Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putStringExtra("keyForData", Value);
startActivity(intent);

2番目のアクティビティでコードを書く:-

Intent intent = Activity2.this.getIntent();
String data  =intent.getStringExtra("KeyForData");
于 2012-08-11T12:31:33.980 に答える
0

1.にデータを送信するためIntentに とともに使用します。putExtra()Another Activity

例えば:

   Intent i = new Intent(Your_Class.this, Desired_Class.class);

   i.putExtra("NameKey","name");

   startActivity(i);

2.受信アクティビティで を使用getIntent()してを取得し、および を使用 してキーに関連付けられた文字列値を取得します。などもあります..Starting IntentgetExtras()getString()getInt()

例えば:

   Intent intent = getIntent();

   String name = intent.getExtras().getString("NameKey");
于 2012-08-11T12:58:11.957 に答える