Java 可扩展回收视图

Java 可扩展回收视图,java,android,mobile,android-recyclerview,expandablerecyclerview,Java,Android,Mobile,Android Recyclerview,Expandablerecyclerview,我在项目中工作,我需要可扩展的回收视图。我什么都做了,但对每个“家长”的“孩子”(行)都有一些问题 这是我的“父母”代码。循环视图上的第一项是“选项1”,第二项是“选项2”,依此类推 public TitleCreator(Context context) { _titleParents = new ArrayList<>(); TitleParent title = new TitleParent(String.format("Option 1"));

我在项目中工作,我需要可扩展的回收视图。我什么都做了,但对每个“家长”的“孩子”(行)都有一些问题

这是我的“父母”代码。循环视图上的第一项是“选项1”,第二项是“选项2”,依此类推

 public TitleCreator(Context context) {
    _titleParents = new ArrayList<>();


        TitleParent title = new TitleParent(String.format("Option 1"));
        _titleParents.add(title);
        TitleParent title1 = new TitleParent(String.format("Option 2"));
        _titleParents.add(title1);
        TitleParent title2 = new TitleParent(String.format("Option 3"));
        _titleParents.add(title2);
        TitleParent title3 = new TitleParent(String.format("Option 4"));
        _titleParents.add(title3);
        TitleParent title4 = new TitleParent(String.format("Option 5"));
        _titleParents.add(title4);

}
公共标题创建者(上下文){
_titleParents=新的ArrayList();
TitleParent title=新的TitleParent(String.format(“选项1”);
_标题当事人。添加(标题);
TitleParent title1=新的TitleParent(String.format(“选项2”));
_标题当事人。添加(标题1);
TitleParent title2=新的TitleParent(String.format(“选项3”);
_标题当事人。添加(标题2);
TitleParent title3=新的TitleParent(String.format(“选项4”);
_标题当事人。添加(标题3);
TitleParent title4=新的TitleParent(String.format(“选项5”);
_标题当事人。添加(标题4);
}
它工作得很好,但当我想为每个父母的孩子做同样的事情时,我遇到了一个问题。最后,我在MainActivity中编写了一些代码,使每个父级的每个子级都相同。代码如下:

 private List<ParentObject> initData() {
    TitleCreator titleCreator = TitleCreator.get(this);
    List<TitleParent> titles = titleCreator.getAll();
    List<ParentObject> parentObject = new ArrayList<>();
    for(TitleParent title:titles)
    {
        List<Object> childList = new ArrayList<>();
        childList.add(new TitleChild("Combe","Send message"));
        title.setChildObjectList(childList);
        parentObject.add(title);
    }
    return parentObject;

}
private List initData(){
TitleCreator TitleCreator=TitleCreator.get(this);
列表标题=titleCreator.getAll();
List parentObject=new ArrayList();
用于(标题家长标题:标题)
{
List childList=new ArrayList();
添加(新标题child(“Combe”,“Send message”);
title.setChildObjectList(childList);
parentObject.add(标题);
}
返回parentObject;
}

每个家长需要不同的子/行,如何做到这一点?

每个家长需要不同的子/行

public TitleCreator(Context context) {
    _titleParents = new ArrayList<>();

    TitleParent title = new TitleParent(String.format("Option 1"));
    _titleParents.add(title);
    List<Object> childList = new ArrayList<>();
    childList.add(new TitleChild("Combe1","Send message"));
    title.setChildObjectList(childList);

    TitleParent title1 = new TitleParent(String.format("Option 2"));
    _titleParents.add(title1);
    childList = new ArrayList<>();
    childList.add(new TitleChild("Combe2","Send message"));
    title1.setChildObjectList(childList);

    TitleParent title2 = new TitleParent(String.format("Option 3"));
    _titleParents.add(title2);
    childList = new ArrayList<>();
    childList.add(new TitleChild("Combe3","Send message"));
    title2.setChildObjectList(childList);

    TitleParent title3 = new TitleParent(String.format("Option 4"));
    _titleParents.add(title3);
    childList = new ArrayList<>();
    childList.add(new TitleChild("Combe4","Send message"));
    title3.setChildObjectList(childList);

    TitleParent title4 = new TitleParent(String.format("Option 5"));
    _titleParents.add(title4);
    childList = new ArrayList<>();
    childList.add(new TitleChild("Combe5","Send message"));
    title4.setChildObjectList(childList);
}
公共标题创建者(上下文){
_titleParents=新的ArrayList();
TitleParent title=新的TitleParent(String.format(“选项1”);
_标题当事人。添加(标题);
List childList=new ArrayList();
添加(新标题child(“Combe1”,“发送消息”);
title.setChildObjectList(childList);
TitleParent title1=新的TitleParent(String.format(“选项2”));
_标题当事人。添加(标题1);
childList=newarraylist();
添加(新标题child(“Combe2”,“发送消息”);
标题1.setChildObjectList(儿童列表);
TitleParent title2=新的TitleParent(String.format(“选项3”);
_标题当事人。添加(标题2);
childList=newarraylist();
添加(新标题child(“Combe3”,“发送消息”);
标题2.setChildObjectList(儿童列表);
TitleParent title3=新的TitleParent(String.format(“选项4”);
_标题当事人。添加(标题3);
childList=newarraylist();
添加(新标题child(“组合4”,“发送消息”);
标题3.setChildObjectList(儿童列表);
TitleParent title4=新的TitleParent(String.format(“选项5”);
_标题当事人。添加(标题4);
childList=newarraylist();
添加(新标题child(“Combe5”、“发送消息”);
标题4.setChildObjectList(儿童列表);
}

它不起作用,我在函数initData的MainActivity.java中到底要做什么?你介意使用库吗?@Eminem是的,在build.gradle(应用程序)中我实现了以下库:implementation'com.android.support:recyclerview-v7:27.1.1'implementation'com.android.support:cardview-v7:27.1.1'implementation'com.bignerdranch.android:expandablerecyclerview:1.0.3'