在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, 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中的子选择所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)