Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何显示3级以上的可扩展列表视图?_Android_User Interface_Expandablelistview - Fatal编程技术网

Android 如何显示3级以上的可扩展列表视图?

Android 如何显示3级以上的可扩展列表视图?,android,user-interface,expandablelistview,Android,User Interface,Expandablelistview,如何显示3级以上的可扩展列表视图,我只得到3级可扩展列表视图的示例 关于这一点: 在本例中,他在ParentLevelBaseExpandableListAdapter的getChildView方法中添加了一个可扩展列表: CustExpListview SecondLevelexplv = new CustExpListview(Home.this); SecondLevelexplv.setAdapter(new SecondLevelAdapter()); SecondLevelexpl

如何显示3级以上的可扩展列表视图,我只得到3级可扩展列表视图的示例

关于这一点:

在本例中,他在ParentLevel
BaseExpandableListAdapter
getChildView
方法中添加了一个可扩展列表:

CustExpListview SecondLevelexplv = new CustExpListview(Home.this);
SecondLevelexplv.setAdapter(new SecondLevelAdapter());

SecondLevelexplv.setGroupIndicator(null);   
return SecondLevelexplv;
同样地,我在
SecondLevelAdapter
getChildView
方法中添加了一个可扩展列表

它的工作,但视图是不来正确的像3级的可扩展列表视图。 我读过:

请指导或分享我在android中的多级可扩展显示的合适示例


谢谢,

我找到了解决方案,我正在上传所有java类,所以请检查所有java或您可以检查:

public class CustExpListview extends ExpandableListView {

    public CustExpListview(Context context) {
        super(context);
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        widthMeasureSpec = MeasureSpec.makeMeasureSpec(960, MeasureSpec.AT_MOST);
        heightMeasureSpec = MeasureSpec.makeMeasureSpec(600, MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onDetachedFromWindow() {
        try {
            super.onDetachedFromWindow();
        } catch (IllegalArgumentException e) {
            // TODO: Workaround for
            // http://code.google.com/p/android/issues/detail?id=22751
        }
    }
}
1:MainActivity.java

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Object  obj = new Object();
    obj.children =  new ArrayList<Object>();
    for(int i = 0;i<Constant.state.length;i++)
    {
        Object root =  new Object();
        root.title = Constant.state[i];
        root.children =  new ArrayList<Object>();
        for(int j=0;j<Constant.parent[i].length;j++)
        {
             Object parent =  new Object();
             parent.title=Constant.parent[i][j];
             parent.children =  new ArrayList<Object>();
             for(int k=0;k<Constant.child[i][j].length;k++)
             {
                 Object child =  new Object();
                 child.title =Constant.child[i][j][k];
                 parent.children.add(child);
             }
             root.children.add(parent); 
        }
        obj.children.add(root);
    }

    if (!obj.children.isEmpty()) {
        final ExpandableListView elv = (ExpandableListView) findViewById(R.id.expList);

        elv.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

            @Override
            public boolean onGroupClick(ExpandableListView parent, View v,
                    int groupPosition, long id) {

                return true; /* or false depending on what you need */;
            }
        });


        ExpandableListView.OnGroupClickListener grpLst = new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView eListView, View view, int groupPosition,
                    long id) {

                return true/* or false depending on what you need */;
            }
        };


        ExpandableListView.OnChildClickListener childLst = new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView eListView, View view, int groupPosition,
                    int childPosition, long id) {

                return true/* or false depending on what you need */;
            }
        };

        ExpandableListView.OnGroupExpandListener grpExpLst = new ExpandableListView.OnGroupExpandListener() {
            @Override
            public void onGroupExpand(int groupPosition) {

            }
        };

        final RootAdapter adapter = new RootAdapter(this, obj, grpLst, childLst, grpExpLst);
        elv.setAdapter(adapter);
}


}
 }
5.java

public class Constant {
static String[] state = {"A","B","C"};
static  String[][] parent = {
        {"aa","bb","cc","dd","ee"},
        {"ff","gg","hh","ii","jj"},
        {"kk","ll","mm","nn","oo"}
    };

static  String[][][] child = {
            {
                {"aaa","aab","aac","aad","aae"},
                {"bba","bbb","bbc","bbd","bbe"},
                {"cca","ccb","ccc","ccd","cce","ccf","ccg"},
                {"dda","ddb","dddc","ddd","dde","ddf"},
                {"eea","eeb","eec"}
            },
            {
                {"ffa","ffb","ffc","ffd","ffe"},
                {"gga","ggb","ggc","ggd","gge"},
                {"hha","hhb","hhc","hhd","hhe","hhf","hhg"},
                {"iia","iib","iic","iid","iie","ii"},
                {"jja","jjb","jjc","jjd"}
            },
            {
                {"kka","kkb","kkc","kkd","kke"},
                {"lla","llb","llc","lld","lle"},
                {"mma","mmb","mmc","mmd","mme","mmf","mmg"},
                {"nna","nnb","nnc","nnd","nne","nnf"},
                {"ooa","oob"}
            }
        };
}
5:item_parent.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="10dp" >

<TextView
    android:id="@+id/itemParentTitle"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:background="#5ccccc"
    android:padding="2dp"
    android:textColor="#006363"
    android:textSize="20sp" />

<ImageView
    android:id="@+id/itemParentImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</LinearLayout>

使用消耗性列表视图并制作第二个消耗性适配器是一种不推荐的方法。它会使整个过程变得复杂。有一种简单的方法,通过使用滚动视图和内部线性布局来扩展不同的视图

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
{
    // 999999 is a size in pixels. 
    // ExpandableListView requires a maximum height in order to do measurement calculations.
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(999999, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

这使得长度更加合理。

您所说的“其工作但视图不正常”是什么意思?所有子视图都应可见并可滚动,但只有第一级和第二级视图正确可见并可滚动。第三级的所有子项都不可见,也不能滚动。你可以发布你的xml文件吗Checkout Ya我已经检查了这个链接,但是如果列表大小比这个链接中的大,你也有同样的问题。问题是onMesure()方法。你能与我共享你的项目吗方法和我创建的示例应用程序与问题中的相同。嘿,你能发布所有xml文件吗?第二个子视图如何设置为填充父视图作为宽度如果我将其设置为填充父视图,则右侧图像未显示,请帮我解决此问题,提前感谢。请清除您的问题您正在尝试在第三级添加图像视图,并且您还希望视图作为填充父视图或任何其他内容。感谢您的回复,在第二级中,我设置了布局,其中我有一个属性为align\u parentRight=“true”的ImageView,但该ImageView未显示,同样的布局也用于父视图,它显示ImageView,为什么会发生这种情况。在MainActivity.java类中有ExpandableListView.OnGroupClickListener grpLst这是第二级listner和ExpandableListView.OnChildClickListener childLst这是第三级listnerchlid列表未打开这更像是对现有答案的注释,而不是新答案。实际上,我正在发布一个链接,您可以在其中看到找到一种有效的方法,使消耗性列表视图二级适配器不能正常工作,并且其中出现了一些复杂的情况,一些功能不能正常工作,这是非常奇怪的。我的第二级标题显示错误,高度为2000像素(它是向左对齐的),最好是600像素,但当它有5行以上时,一些行变成了外部视图。但有了你的建议,一切都很顺利。你知道吗,像素的最大值是多少,我可以设置为多个级别正常工作吗?我找到了一些代码,但目前找不到。999999是最大尺寸,因此计算基于最大数量,然后计算为实际尺寸。但其他代码并没有像预期的那样工作,但999999工作得很好。当做
public class Constant {
static String[] state = {"A","B","C"};
static  String[][] parent = {
        {"aa","bb","cc","dd","ee"},
        {"ff","gg","hh","ii","jj"},
        {"kk","ll","mm","nn","oo"}
    };

static  String[][][] child = {
            {
                {"aaa","aab","aac","aad","aae"},
                {"bba","bbb","bbc","bbd","bbe"},
                {"cca","ccb","ccc","ccd","cce","ccf","ccg"},
                {"dda","ddb","dddc","ddd","dde","ddf"},
                {"eea","eeb","eec"}
            },
            {
                {"ffa","ffb","ffc","ffd","ffe"},
                {"gga","ggb","ggc","ggd","gge"},
                {"hha","hhb","hhc","hhd","hhe","hhf","hhg"},
                {"iia","iib","iic","iid","iie","ii"},
                {"jja","jjb","jjc","jjd"}
            },
            {
                {"kka","kkb","kkc","kkd","kke"},
                {"lla","llb","llc","lld","lle"},
                {"mma","mmb","mmc","mmd","mme","mmf","mmg"},
                {"nna","nnb","nnc","nnd","nne","nnf"},
                {"ooa","oob"}
            }
        };
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="10dp" >

<TextView
    android:id="@+id/itemParentTitle"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:background="#5ccccc"
    android:padding="2dp"
    android:textColor="#006363"
    android:textSize="20sp" />

<ImageView
    android:id="@+id/itemParentImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</LinearLayout>
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
{
    // 999999 is a size in pixels. 
    // ExpandableListView requires a maximum height in order to do measurement calculations.
    heightMeasureSpec = MeasureSpec.makeMeasureSpec(999999, MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}