Android 如何将ArrayList的数据值获取给其他活动

Android 如何将ArrayList的数据值获取给其他活动,android,Android,嘿,我在activity1.class中有一个arraylist,我想从该数组中获取数据,以显示activity2.class中的数据eposodeList.size(),这里是我的列表代码 public class EpisodeAdapter extends RecyclerView.Adapter<EpisodeAdapter.EpisodeHolder>{ private List<Episode> episodeList; public Ep

嘿,我在activity1.class中有一个arraylist,我想从该数组中获取数据,以显示activity2.class中的数据eposodeList.size(),这里是我的列表代码

public class EpisodeAdapter  extends  RecyclerView.Adapter<EpisodeAdapter.EpisodeHolder>{
    private List<Episode> episodeList;
    public EpisodeAdapter(List<Episode> episodeList) {
        this.episodeList = episodeList;
    }
    @Override
    public EpisodeHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_episode , null);
        EpisodeAdapter.EpisodeHolder mh = new EpisodeAdapter.EpisodeHolder(v);
        return mh;
    }

public int getItemCount() {
        return episodeList.size();
    }
公共类eposodeAdapter扩展了RecyclerView.Adapter{
私密书名;
公共音标适配器(列表音标列表){
this.eposodelist=eposodelist;
}
@凌驾
public eposodeholder onCreateViewHolder(视图组父级,int-viewType){
视图v=LayoutInflater.from(parent.getContext()).flate(R.layout.item_,null);
EpisodeAdapter.EpisodeHolder mh=新的EpisodeAdapter.EpisodeHolder(v);
返回mh;
}
public int getItemCount(){
返回eposodelist.size();
}
你可以通过

ArrayList<Episodes> list=getIntent.getparcelableArrayList("episodeList")
ArrayList list=getIntent.getparcelableArrayList(“情节列表”)

不要忘记将模型类设置为可包裹的

您可以使用意图将值从一个活动传递到另一个活动,如下所示: 在要传递ArrayList的当前活动中:

Intent intent = new Intent(CurrentActivity.this, TargetActivity.class);
intent.putStringArrayListExtra("key", your_array_list);
startActivity();
在您希望接收值的活动中:

Intent intent = getIntent();  
ArrayList arrayList= intent.getStringArrayListExtra("key");

我的项目也有同样的问题。我只是使用了SharedReferences。它就像项目中的本地文件,但你看不到它。你只需将值放入其中,然后在第二个活动中检索它们

有关更多信息:

在ArrayList模型中实现Parcelable


您可以带着意图发送该列表,也可以将其存储在本地数据库或strings.xml中,以便从任何位置访问它使用可解析的发送ArrayList,然后使用bundle.putParceableArrayList(键,列表)发送它。这是否回答了您的问题?
并且不要忘记将模型类设置为可包裹的
请将此部分添加到您的问题中以使其完整只需像这样实现即可…类插曲实现可包裹
Intent intent = getIntent();  
ArrayList arrayList= intent.getStringArrayListExtra("key");
Intent intent = new Intent(context, ServiceDetailActivity.class);
intent.putParcelableArrayListExtra("key", (ArrayList<? extends Parcelable>) arrayList);
startActivity(intent);
arrayList = getIntent().getParcelableArrayListExtra("key");