Android   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – ExpandableListView中的子选择大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

在ExpandableListView中,是否可以初始选择子项,以便扩展包含组并将列表滚动到该子项的位置?

我认为setSELEctedChild可以做到这一点,但它没有给出任何结果.

我测试了以下代码

public class MainActivity extends Activity {

private static final String titlE = "title";

@SuppressWarnings("serial")
@Override
protected void onCreate(Bundle savedInstanceStatE) {
    super.onCreate(savedInstanceStatE);

    ExpandableListView listView = new ExpandableListView(this);
    Simpleexpandablelistadapter adapter = new Simpleexpandablelistadapter(this, 
        new ArrayList<Map<String,String>>() {
            {
                this.add(new HashMap<String, String>() {
                    {
                        this.put(titlE, "Group 1");
                    }
                });
                this.add(new HashMap<String, String>() {
                    {
                        this.put(titlE, "Group 2");
                    }
                });
                this.add(new HashMap<String, String>() {
                    {
                        this.put(titlE, "Group 3");
                    }
                });
            }
        }, 
        android.R.layout.simple_expandable_list_item_1, 
        new String[] { titlE }, 
        new int[] { android.R.id.text1 }, 
        new ArrayList<List<? extends Map<String,String>>>() {
            {
                this.add(new ArrayList<Map<String,String>>() {
                    {
                        this.add(new HashMap<String, String>() {
                            {
                                this.put(titlE, "Child 1-1");
                            }
                        });
                        this.add(new HashMap<String, String>() {
                            {
                                this.put(titlE, "Child 1-2");
                            }
                        });
                    }
                });
                this.add(new ArrayList<Map<String,String>>() {
                    {
                        this.add(new HashMap<String, String>() {
                            {
                                this.put(titlE, "Child 2-1");
                            }
                        });
                        this.add(new HashMap<String, String>() {
                            {
                                this.put(titlE, "Child 2-2");
                            }
                        });
                    }
                });
                this.add(new ArrayList<Map<String,String>>() {
                    {
                        this.add(new HashMap<String, String>() {
                            {
                                this.put(titlE, "Child 3-1");
                            }
                        });
                        this.add(new HashMap<String, String>() {
                            {
                                this.put(titlE, "Child 3-2");
                            }
                        });
                    }
                });
            }
        },
        android.R.layout.simple_expandable_list_item_2,
        new String[] { titlE },
        new int[] { android.R.id.text1 }
    );
    listView.setAdapter(adapter);
    setContentView(listView);

    listView.setSELEctedChild(1, 1, truE);
}
}

解决方法:

在setSELEctedChild()之前添加对listView.expandGroup()的调用.

在setSELEctedChild()中设置为true的shouldExpandGroup参数似乎只有在首先扩展了至少一个组时才起作用.

大佬总结

以上是大佬教程为你收集整理的android – ExpandableListView中的子选择全部内容,希望文章能够帮你解决android – ExpandableListView中的子选择所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: