0
我有以下代码完美运行。当用户点击一个组并且由于状态的改变而扩大图像变化时。 xml文件也在下面。我遇到的问题是当我点击一个子元素时,它开始一个新的活动,但在你看到图像改变状态之前就好像该组关闭了一样。当您使用后退箭头时,即使该组仍处于展开状态,该图像也确实回到了关闭状态。任何人都可以对此有所了解吗?点击可扩展Listview图像变化?
private static final int[] EMPTY_STATE_SET = {};
private static final int[] GROUP_EXPANDED_STATE_SET = {android.R.attr.state_expanded};
private static final int [] [] GROUP_STATE_SETS = {
EMPTY_STATE_SET, //0
GROUP_EXPANDED_STATE_SET //1
};
Cursor groupCursor = checkDB.rawQuery("SELECT * FROM TABLE", null);
mscta = new MySimpleCursorTreeAdapter(
this,
groupCursor,
R.layout.listGroup,
new String[] {"group"},
new int[] {R.id.group},
R.layout.listChildren,
new String[] {"child"},
new int[] {R.id.Child}) {
@Override
public View getGroupView (int groupPosition,
boolean isExpanded,
View convertView,
ViewGroup parent) {
View v = super.getGroupView(groupPosition, isExpanded, convertView, parent);
View ind = v.findViewById(R.id.explist_indicator);
if(ind != null){
ImageView indicator = (ImageView) ind;
indicator.setVisibility(View.VISIBLE);
int stateSetIndex = (isExpanded ? 1:0);
Drawable drawable = indicator.getDrawable();
drawable.setState(GROUP_STATE_SETS[stateSetIndex]);
}
return v;
}
};
XML explist_indicator.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_expanded="true"
android:drawable="@drawable/minus" />
<item
android:drawable="@drawable/plus" />
</selector>