0

editText の値をクラスから別のクラスに渡そうとしています。最初のクラスでは、次のコードを使用して editText の値を取得します。

number = (EditText) this.findViewById(R.id.editText10);
text=number.getText().toString();//obtain the value

ここで、「テキスト」は静的文字列です。STATIC後で、文字列「text」を返す次のコードを使用します。

public static String rete()   
{
    return text;
}

最後に、これを使用して 2 番目のクラスの値を取得します。

String text2 = Pruebita2.rete();

Pruebita2最初のクラスの名前はどこにありますか。

私は何を間違っていますか?

4

1 に答える 1

0

クラス間でデータを転送する最も簡単な方法は、インテントを介して文字列「テキスト」を 2 番目のクラスに渡すことです。

例えば。

アクティビティ 1: インテントを作成する

Intent intent = new Intent(this, Activity2.class);
           intent.putExtra("text_key", text); 
           context.startActivity(intent);

アクティビティ 2: 値を取得する

text = getIntent().getStringExtra("text_key");
于 2013-07-06T19:45:06.910 に答える