8

2 分数配列オブジェクトをパラメーターとして別のアクティビティに渡す方法

別のアクティビティで 2 次元配列の文字列値を取得する方法

   String [][]str;

    Intent l = new Intent(context,AgAppMenu.class);
                 l.putExtra("msg",str);
                 l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
                 context.startActivity(l);



  another Activity class

   String[][] xmlRespone2;

    xmlRespone2 = getIntent().getExtras().getString("msg");
4

5 に答える 5

14

putSerializableを使用できます。配列はシリアライズ可能です。

保存するには:

bundle.putSerializable("list", selected_list); // ここで bundle は Bundle オブジェクトです。

アクセスするために:

String[][] passedString_list = (String[][]) bundle.getSerializable("list");

Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.putSerializable("list", selected_list);
mIntent.putExtras(mBundle);
于 2012-08-31T12:00:06.147 に答える
6

これは最終的に私にとってうまくいきます:

新しいアクティビティを開始するには (String[][] と String を送信):

String[][] arrayToSend=new String[3][30];
String stringToSend="Hello";
Intent i = new Intent(this, NewActivity.class);

i.putExtra("key_string",stringToSend);

Bundle mBundle = new Bundle();
mBundle.putSerializable("key_array_array",  arrayToSend);
i.putExtras(mBundle);

startActivity(i);

NewActivity.onCreate でアクセスするには:

String sReceived=getIntent().getExtras().getString("key_string");

String[][] arrayReceived=null;
Object[] objectArray = (Object[]) getIntent().getExtras().getSerializable("key_array_array");
if(objectArray!=null){
    arrayReceived = new String[objectArray.length][];
    for(int i=0;i<objectArray.length;i++){
        arrayReceived[i]=(String[]) objectArray[i];
    }
}
于 2013-09-28T13:38:59.793 に答える
2

Parcelableパーセルとの間で 2 次元配列を読み書きするためのロジックを実装および含むカスタム クラスを定義できます。その後、その小分け可能なオブジェクトBundleを輸送のために中に入れます。

于 2012-08-31T11:58:05.837 に答える
0

2darray を public static void として設定します。current_class を 2 次元配列を作成するクラスにしますデータを NewActivity に渡します

Class<?> ourClass=Class.forName("com.example.testapp.NewActivity");
Intent ourIntent= new Intent(current_class.this,ourClass);
intent_name.putExtra("name", 2darray_name);
startActivity(ourIntent);`

NewActivity でこれにアクセスするには、 current_class.2darray_name を使用します。 current_class は、最初に定義されたクラスです。

于 2013-10-23T21:03:56.420 に答える
-1

1つの解決策は、それを静的として設定して、任意のアクティビティで使用できるようにすることです。

Class A{
 public static String [][]str;
...
    Intent l = new Intent(context,AgAppMenu.class);
                 l.putExtra("msg",str);
                 l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);   
                 context.startActivity(l);


}

Class B{

...
you can use it with Just A.(ArrayName)
System.out.println(A.str);

}

それがあなたを助けることを願っています。

于 2012-08-31T12:00:47.987 に答える