我在从一个活动到另一个活动中检索ArrayList时遇到问题。 My Video类实现了Parcelable。
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bundle b = mVideos.get(numero).getAsBundle();
Bundle a = new Bundle();
// putting the parcelable mVideos, which is an array, into the bundle.
a.putParcelableArrayList("videos", mVideos);
final Intent i = new Intent("com.video.tv.description");
i.putExtra("com.video.tv.description", b);
i.putExtra("com.video.tv.Videos", a); // I added it to intent
dAct.startActivity(i);
}
});
如何在第二个活动中检索整个数组?
Bundle a = i.getBundleExtra("com.video.tv.Videos")??
我正试图在我的初始活动之前获得整个阵列。
答案 0 :(得分:0)
你的代码非常奇怪,看起来你有很多不必要的捆绑包和东西漂浮在你构建你的捆绑包时尝试以下内容:
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// What is the purpose of this line?
Bundle b = mVideos.get(numero).getAsBundle();
Bundle a = new Bundle();
a.putParcelableArrayList("videos", mVideos);
// Replace YourNewActivity with the name of the Activity you want to start.
Intent i = new Intent(dAct, YourNewActivity.class);
i.putExtra("description", b);
i.putExtra("videos", a); // I added it to intent
dAct.startActivity(i);
}
});
然后,在您的接收活动中,执行以下操作以获取列表:
Bundle i = getIntent().getExtras();
Bundle a = i.getBundleExtra("com.video.tv.Videos");
ArrayList<Video> videos = a.getParcelableArrayList("videos");