Answer the question
In order to leave comments, you need to log in
How to make ExpandableList inside child ExpandableList?
You need to create a file tree on android. Correct me if I'm going the wrong way.
For this I am using ExpandableList and its adapter.
The code is standard:
I send the data to the adapter and assign the adapter to the ExpandableList element.
group.add(new Dirr (0, co2, path2, name2, typ2, chi2));
ExpListAdapter adapter = new ExpListAdapter(0, getActivity().getApplicationContext(), group, true, 0);
listView.setAdapter(adapter);
public class ExpListAdapter extends BaseExpandableListAdapter {
private int mi;
private ArrayList<Dirr> mGroups;
private Context mContext;
private int yt=0;
public ExpListAdapter (int idd, Context context, ArrayList<Dirr> group, boolean all, int childid){
mi=idd;
mContext = context;
mGroups = group;
yt=1;
}
@Override
public int getGroupCount() {
return mGroups.get(mi).size();
}
@Override
public int getChildrenCount(int groupPosition) {
return yt;
}
@Override
public Object getGroup(int groupPosition) {
return mGroups.get(mi).getname(groupPosition);
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.group_view, null);
}
TextView textGroup = (TextView) convertView.findViewById(R.id.textGroup);
textGroup.setText(mGroups.get(mi).getname(groupPosition));
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.child_view, null);
}
ExpandableListView listView = (ExpandableListView) convertView.findViewById(R.id.expandableListView2);
ExpListAdapter adapter = new ExpListAdapter(mi, getActivity().getApplicationContext(), mGroups, false, childPosition);
listView.setAdapter(adapter);
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textGroup"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="20dp"
android:textColor="@android:color/white"
android:textStyle="bold"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ExpandableListView
android:id="@+id/expandableListView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:indicatorLeft="250dp"
android:indicatorRight="300dp" >
</ExpandableListView>
</LinearLayout>
Answer the question
In order to leave comments, you need to log in
no. It's too easy and wrong. I know about this method. Thank you.
I think if I manage to solve this, then it will pull on a whole article on Habré)). Since the theme of trees on android is poorly lit and elaborated. And it's not a fact that someone did it at all through ExpandableList.
UPD: Resolved the issue. All the same, I used https://github.com/Polidea/tree-view-list-android
The interface component does not affect the data arrays that will be displayed. Based on this, in general, you can use any interface - even textview. Of course, it is not easy to write a tree in Java with any interface. expandeblelist, on the contrary, complicates the task with its additional calls for expanding and collapsing. In general, this is the interface that is least suitable for building trees! tree-view-list-android - designed well enough to do anything on it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question