5

Android で、あるアクティビティから別のアクティビティに文字列配列の ArrayList を渡したいと考えています。
またはをどのように使用できますintentbundle? intent.putStringArrayListExtra文字列配列用ではないため、この場合は機能しないと考えてください。

4

4 に答える 4

1

これが実行可能かどうかはわかりませんが、Bundle クラスに対応しているため、ArrayList を格納するカスタム オブジェクトを実装します。これは、両方のアクティビティでアクセスする必要がある他の共通データを格納するための適切なクリーン ソリューションです。

public class MyCustomData implements Serializable {

    static final long serialVersionUID = 42432432L;
    public ArrayList<String[]> strings = new ArrayList<String[]>();

    public MyCustomData() {

    };
}

そしてあなたの活動で:

MyCustomData myCustomDataInstance = new MyCustomData();
myCustomDataInstance.strings = //set it here;

Bundle bundle = new Bundle();
Intent selectedIntent = new Intent(getActivity(), MyNextClass.class);
bundle.putSerializable("key", myCustomDataInstance);
selectedIntent.putExtras(bundle);
startActivity(selectedIntent);

また、配列の配列リストの代わりに配列リストの配列リストを使用することをお勧めします

于 2013-07-03T16:39:16.387 に答える
0

では、文字列のリストではなく、文字列配列のリストを渡したいのではないでしょうか? はシリアライズ可能であるためArrayList、非常に簡単に追加できます。

ArrayList<String[]> list = new ArrayList<String[]>();
// Add some String[]
Intent i = new Intent();
i.putExtra("xxx", list);

// And to get it back
ArrayList<String[]> list = (ArrayList<String[]>) i.getSerializableExtra("xxx");
于 2013-07-03T16:35:51.280 に答える