问题描述
我是新来的Android。
I am new to Android.
我有一个 ExpandableListView
,在那里我已经成功地突出(永久)所选择的项目/子。但是,当我点击/摸组,突出显示的项目将消失,好像名单已重画。在 onGroupClick
,我尽量保持突出显示的项目突出,但即使如此,它重绘列表。
I have a ExpandableListView
, where I have managed to highlight (persistent) the selected item/child. But when I click/touch the group, the highlighted item goes away and seems like list has been redrawn. In onGroupClick
, I am try to keep the highlighted item highlighted, but even then it redraws the list.
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// TODO keepSelectedModuleHighlited. Right now its not working.
if (parent.isGroupExpanded(groupPosition)) {
parent.collapseGroup(groupPosition);
} else {
parent.expandGroup(groupPosition);
}
keepSelectedModuleHighlited();
return true;
}
和方法:keepSelectedModuleHighlited
And method : keepSelectedModuleHighlited
private void keepSelectedModuleHighlited() {
if (lastSelectedView != null && lastSelectedDrawble != null) {
lastSelectedView.setBackgroundDrawable(this.getResources()
.getDrawable(R.drawable.module_selected));
}
}
我怎样才能把我的方法只是后重绘列表?任何想法?
How can I put my method just after it redraws the list? Any Idea?
推荐答案
由于当Android的重绘列表,它会调用 getChildView()
在 ExpandableListAdapter
,你需要把你的高亮code在 getChildView()
。
Since when Android "redraws the list", it calls getChildView()
on your ExpandableListAdapter
, you need to put your highlighting code in getChildView()
.
这篇关于为什么OnGroupClick重绘ExpandableList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!