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>