0

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> 

그래서 나는 Androidstate_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의 출력은 다음과 같습니다

  1. GetGroupView : 호출!
  2. 으로 IsExpanded은 다음과 같습니다 사실
  3. 주 인덱스 : 1

indicator은 동일하게 유지됩니다.

답변

1

오랜 연구와 시행 착오 끝에 나는 국가와 함께 작동시키는 방법을 찾지 못했습니다. 그러나, 나는 다음과 같은 이미지 자체 사용 : 슬프게도

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 (indicator != null) { 
     ImageView indicatorImage = (ImageView) indicator; 
     if (getChildrenCount(groupPosition) == 0) { 
      indicatorImage.setVisibility(View.INVISIBLE); 
     } else { 
      indicatorImage.setVisibility(View.VISIBLE); 

      if (isExpanded) { 
       indicatorImage.setImageResource(R.drawable.arrow_up); 
      } else { 
       indicatorImage.setImageResource(R.drawable.arrow_down); 
      } 
     } 
    } 

    ... 
} 

, 드로어 블와 청소기 솔루션을하고 상태가 작동되지 않았습니다. 다른 사람들이이 질문에 걸리는 데 도움이되기를 바랍니다.