0

나는 이와 관련하여 SO에 대해 몇 가지 질문을 겪었습니다.3 단계 확장 가능 목록보기 Android

두 번째 레벨을 클릭하면 펼칠 수있는 목록에 최대 2 개의 레벨을 표시 할 수 있지만 세 번째 레벨을 표시 할 수 없습니다.

것은 그래서 같은 것을 시도했다 : -

ParentView (첫 번째 수준)

public class ParentView : BaseExpandableListAdapter 
    { 
     public static int FIRST_LEVEL_COUNT = 6; 
     public static int SECOND_LEVEL_COUNT = 4; 
     public static int THIRD_LEVEL_COUNT = 10; 
     private Context context; 



     public ParentView(Context context) 
     { 
      this.context = context; 
     } 

     public ParentView() 
     { 
     } 

     public override Java.Lang.Object GetChild(int groupPosition, int childPosition) 
     { 
      return childPosition; 
     } 


     public override long GetChildId(int groupPosition, int childPosition) 
     { 
      return childPosition; 
     } 



     public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent) 
     { 
      var SecondLevelexplv = new CustExpListview(Application.Context); 
      SecondLevelexplv.SetAdapter(new SecondLevelAdapter(context)); 
      SecondLevelexplv.SetGroupIndicator(null); 
      return SecondLevelexplv; 
     } 

     public override int GetChildrenCount(int groupPosition) 
     { 
      return 3; 
     } 

     public override Java.Lang.Object GetGroup(int groupPosition) 
     { 
      return groupPosition; 
     } 
     public override int GroupCount 
     { 
      get 
      { 
       return 5; 
      } 
     } 

     public override long GetGroupId(int groupPosition) 
     { 
      return groupPosition; 
     } 

     public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent) 
     { 
      var tv = new TextView(Application.Context) 
      { 
       Text = "->FirstLevel", 
      }; 
      tv.SetBackgroundColor(Color.Blue); 
      tv.SetPadding(10, 7, 7, 7); 

      return tv; 
     } 

     public override bool IsChildSelectable(int groupPosition, int childPosition) 
     { 
      return true; 
     } 

     public override bool HasStableIds 
     { 
      get 
      { 
       return true; 
      } 
     } 

    } 

CustExpListView

public class CustExpListview : ExpandableListView 
{ 

public CustExpListview(Context context) : base(context) 
{ 
} 

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
{ 
    widthMeasureSpec = MeasureSpec.MakeMeasureSpec(999999, MeasureSpecMode.AtMost); 
    heightMeasureSpec = MeasureSpec.MakeMeasureSpec(999999, MeasureSpecMode.AtMost); 
    OnMeasure(widthMeasureSpec, heightMeasureSpec); 
} 
} 

SecondLevelAdapter

public class SecondLevelAdapter : BaseExpandableListAdapter 
{ 
public static int THIRD_LEVEL_COUNT = 10; 
private Context context; 
private readonly ParentView parentView; 

public SecondLevelAdapter(Context context) 
{ 
    this.context = context; 
} 

public SecondLevelAdapter(ParentView parentView) 
{ 
this.parentView = parentView; 
} 

public override Java.Lang.Object GetGroup(int groupPosition) 
{ 
    return groupPosition; 
} 

public override int GroupCount 
{ 
    get 
    { 
     return 5; 
    } 
} 



public override long GetGroupId(int groupPosition) 
{ 
    return groupPosition; 
} 


public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent) 
{ 
    var tv = new TextView(Application.Context) 
    { 
     Text = "-->Second" 
    }; 
    tv.SetPadding(12, 7, 7, 7); 
    tv.SetBackgroundColor(Color.GreenYellow); 

    return tv; 
} 



public override Java.Lang.Object GetChild(int groupPosition, int childPosition) 
{ 
    return childPosition; 
} 

public override long GetChildId(int groupPosition, int childPosition) 
{ 
    return childPosition; 
} 



public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent) 
{ 
    var tv = new TextView(Application.Context) 
    { 
     Text = "third" 
    }; 
    tv.SetPadding(18, 5, 5, 5); 
    tv.SetBackgroundColor(Color.Green); 

    return tv; 
} 


public override int GetChildrenCount(int ChildPosition) 
{ 
    return 4; 
} 


public override bool IsChildSelectable(int groupPosition, int childPosition) 
{ 
    return true; 
} 

public override bool HasStableIds 
{ 
    get 
    { 
     return true; 
    } 
} 

}

내가 알아챈 것은 GetGroup()이 호출되었지만 SecondLevelAdapterGetChildView()이 호출되지 않는다는 것입니다. 실제로 4 레벨까지 목록을 확장하고 싶지만 3 레벨 자체에 붙어 있습니다.

도움을 주시면 감사하겠습니다.

+2

4 수준의 확장 목록 변하기 쉬운? 나는 당신이 [이]와 같이 좀 더 모바일 친화적 인 디자인으로 다시 생각할지도 모른다고 생각합니다. (https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/images/patterns-md-stacked.png). –

+0

@ R.Zagórski 잘 고객이 손상 될 수없는 그런 종류의 요구 사항을 가지고 있습니다. – user3034944

답변

0

문제는 -->Second의 모든 행에 대해 전체적으로 ExpandableListView이며 여기에는 5 개의 그룹이 포함됩니다. 그리고 현재 부모 그룹의 높이가 자식 ExpandableListView에 대해 자동으로 확장되지 않기 때문입니다. 열린 어린이 목록을 볼 수 없습니다 : third.

  1. 변경 1-5에서 SecondLevelAdapterGroupCount :

    문제를 해결하기 위해 할 수있는 몇 가지 변화가있다

    public override int GroupCount 
    { 
        get 
        { 
         //return 5; 
         return 1;//Change GroupCount to 1 
        } 
    } 
    
  2. 당신은의 높이를 변경해야 모든 두 번째 수준의 ExpandableListView 수동으로.

    ParentView.cs : 이것은 GroupExpandGroupCollapse 이벤트를 구현하여 수행 할 수 있습니다 따라서

    public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent) 
    { 
        var SecondLevelexplv = new CustExpListview(Application.Context); 
        SecondLevelexplv.SetAdapter(new SecondLevelAdapter(context)); 
        SecondLevelexplv.SetGroupIndicator(null); 
        SecondLevelexplv.GroupExpand += SecondLevelexplv_GroupExpand; 
        SecondLevelexplv.GroupCollapse += SecondLevelexplv_GroupCollapse; 
        return SecondLevelexplv; 
    } 
    
    private void SecondLevelexplv_GroupCollapse(object sender, ExpandableListView.GroupCollapseEventArgs e) 
    { 
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MatchParent, 70); 
        (sender as CustExpListview).LayoutParameters = lp; 
    } 
    
    private void SecondLevelexplv_GroupExpand(object sender, ExpandableListView.GroupExpandEventArgs e) 
    { 
        //expand the group and the height is the `children count` * `unit height` 
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MatchParent, 70 * 5); 
        (sender as CustExpListview).LayoutParameters = lp; 
    } 
    

를 올바르게 작동합니다

enter image description here

+0

감사합니다. – user3034944