O
O
Oleg2014-05-16 10:26:08
Java
Oleg, 2014-05-16 10:26:08

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);

Adapter code:
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;
}
}

Group_view and child_view code respectively:
<?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>

So there is only one problem - when the ExpandableList is expanded, only 1 row of the child ExpandableList is displayed. How can I make it show all?
Or how to make a tree of files using ExpandableList? What ways?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2014-05-16
@Master255

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.

D
dr_yand, 2014-05-16
@dr_yand

I used to display the tree structure code.google.com/p/tree-view-list-android
There is an example, you can figure out how it works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question