我用
SimpleExpandableListAdapter
在我的
ExpandableListActivity
当用户单击组行时,子列表将展开并显示,当用户单击展开列表中的每个子项时,用户将导航到下一个second_Activity.目前,当用户单击后退按钮从second_Activity返回到ExpandableListActivity时,可扩展列表被初始化为未展开,我希望可扩展列表保持扩展状态,以便用户先前知道他选择了哪个项目.怎么做?应该覆盖ExpandableListActivity中的哪个方法?
PS:我知道我应该放在getExpandableListView().expandGroup(groupPosition);某个地方,但在哪里?我试图把这个代码onGroupClick()和onChildClick(),但是这并没有帮助.
str*_*aya 64
对于总是扩展的组,我扩展SimpleExpandableListAdapter并将组设置为在getGroupView方法中展开:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
ExpandableListView eLV = (ExpandableListView) parent;
eLV.expandGroup(groupPosition);
return v;
}
Run Code Online (Sandbox Code Playgroud)
我正在浏览试图找到我自己的ExpandableListView问题的解决方案.无论如何,将我的2美分加到adstro提供的答案中.
概念很简单:首先调用getGroupCount()ExpandableList Adapter的函数来查找组的数量然后,遍历组并调用expandGroup(int GroupPos)ExpandableList View的函数来扩展每个组.
上面的代码应该放在onCreate()和onResume()之间,以便在创建之后同时满足第一次创建和返回活动的需要.
我做了类似的事情,只是我一直保持所有组的扩展。为了实现这一点,我通过ExpandableListActivity.getExpandableListView()获得了 listView 的句柄,并使用ExpandableListView.expandGroup (int groupPos)来展开组。
对于您的场景,您可以跟踪哪些组已展开,一旦活动再次加载,就重新展开它们。
希望这可以帮助。
另一件事...我将此代码放在 OnCreate() 中。
| 归档时间: |
|
| 查看次数: |
35323 次 |
| 最近记录: |