내 ExpandableListAdapter
에 문제가 있습니다. 메뉴 항목의 왼쪽이 아닌 오른쪽에 위치 시키길 원했기 때문에 맞춤 이미지를 indicator
으로 사용했습니다. 일부 항목에 indicator
을 숨길 필요가 있습니다. 이 같은ExpandableListView 변경 가능 drawable state_expanded
내 당김 외모 :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_expanded="true"
android:drawable="@drawable/arrow_up" />
<item
android:drawable="@drawable/arrow_down" />
</selector>
그래서 나는 Android
의 state_expanded
를 사용합니다.
내 DrawerLayout
는이 LinearLayout
있습니다
<LinearLayout
android:id="@+id/drawer_linear_layout"
android:layout_width="@dimen/menu_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical">
<ExpandableListView
android:id="@+id/navigationmenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:layout_marginTop="@dimen/nav_header_height"
android:childDivider="@android:color/transparent"
android:headerDividersEnabled="true"
android:groupIndicator="@android:color/transparent"
android:background="@drawable/border_shadow">
</ExpandableListView>
</LinearLayout>
내가 코드에서 사용자 정의
Drawable
나중에 추가 수동으로 정상
groupIndicator
을 숨 깁니다.
내
ExpandableListAdapter
올바른 것 같다 :
public class ExpandableListAdapter extends BaseExpandableListAdapter {
...
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
};
...
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
MOMenuItem headerTitle = (MOMenuItem) getGroup(groupPosition);
LayoutInflater infalInflater = (LayoutInflater) this.mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout linLayout = (LinearLayout) infalInflater.inflate(R.layout.list_header, parent, false);
convertView = linLayout;
View indicator = convertView.findViewById(R.id.indicator_image);
if (groupPosition == 1) {
Log.d("GetGroupView", "Called!");
}
if (indicator != null) {
ImageView indicatorImage = (ImageView) indicator;
if (getChildrenCount(groupPosition) == 0) {
indicatorImage.setVisibility(View.INVISIBLE);
} else {
if (groupPosition == 1) {
Log.d("IsExpanded is", "" + isExpanded);
}
indicatorImage.setVisibility(View.VISIBLE);
int stateSetIndex = (isExpanded ? 1 : 0);
if (groupPosition == 1) {
Log.d("State Index", "" + stateSetIndex);
}
Drawable drawable = indicatorImage.getDrawable();
drawable.setState(GROUP_STATE_SETS[stateSetIndex]);
}
}
...
return convertView;
}
}
문제는 indicator
가 업데이트되지 않는다는 것입니다. 그러나, 열 인덱스 1의 항목에 대한 Log
-Statements의 출력은 다음과 같습니다
- GetGroupView : 호출!
- 으로 IsExpanded은 다음과 같습니다 사실
- 주 인덱스 : 1
indicator
은 동일하게 유지됩니다.