android – ExpandableListView中的子选择

android – ExpandableListView中的子选择,第1张

概述在ExpandableListView中,是否可以初始选择子项,以便扩展包含组并将列表滚动到该子项的位置? 我认为setSelectedChild可以做到这一点,但它没有给出任何结果. 我测试了以下代码: public class MainActivity extends Activity {private static final String TITLE = "title";@Supp 在ExpandableListVIEw中,是否可以初始选择子项,以便扩展包含组并将列表滚动到该子项的位置?

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

我测试了以下代码:

public class MainActivity extends Activity {private static final String Title = "Title";@SuppressWarnings("serial")@OverrIDeprotected 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,"Group 2");                    }                });                this.add(new HashMap<String,"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,"Child 1-2");                            }                        });                    }                });                this.add(new ArrayList<Map<String,"Child 2-1");                            }                        });                        this.add(new HashMap<String,"Child 2-2");                            }                        });                    }                });                this.add(new ArrayList<Map<String,"Child 3-1");                            }                        });                        this.add(new HashMap<String,"Child 3-2");                            }                        });                    }                });            }        },androID.R.layout.simple_expandable_List_item_2,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中的子选择所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1122034.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存