Ich habe ein paar Fragen über SO in Bezug auf die gleichen und habe sie ausprobiert.3 Ebene ExpandableListView Android
Ich kann bis zu 2 Ebenen in der erweiterbaren Liste anzeigen, aber ich kann die dritte Ebene nicht anzeigen, wenn ich auf die zweite Ebene klicke.
Ich habe so etwas wie so versucht: -
ParentView (First Level)
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;
}
}
}
Was ich festgestellt habe ist, dass die GetChildView()
in der SecondLevelAdapter
nie aufgerufen wird, obwohl die GetGroup()
aufgerufen wird. Eigentlich möchte ich die Liste auf 4 Ebenen erweitern, aber ich bin auf der 3. Ebene festgefahren.
Jede Hilfe wird geschätzt.
4-Ebene auf erweiterbare Liste Handy, Mobiltelefon? Ich denke, dass Sie Ihr Design überdenken könnten, um so mobiler zu sein wie [this] (https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/images/patterns-md-stacked.png). –
@ R.Zagórski gut der Kunde hat diese Art von Anforderung, die nicht kompromittiert werden kann :) – user3034944