how to use multiple expandablelistview inside scrollview android?
Asked Answered
C

3

9

I want to set 3 expandablelistview in single screen i want to add multiple expandablelistview

XmlLayout

//this is my scorllview
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    tools:context=".fragments.FragmentTestWellnessScoreBoard">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <LinearLayout
            android:id="@+id/llHealth"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/tvHealthTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textStyle="bold"
                android:layout_margin="@dimen/margin_10"
                android:text="Health"/>

            <ExpandableListView
                android:id="@+id/elHealth"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </LinearLayout>


        <LinearLayout
            android:id="@+id/llChallenge"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/tvChallengeTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textStyle="bold"
                android:layout_margin="@dimen/margin_10"
                android:text="Challenge"/>

            <ExpandableListView
                android:id="@+id/elChallenge"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>


        <LinearLayout
            android:id="@+id/llRisk"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/tvRiskTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textStyle="bold"
                android:layout_margin="@dimen/margin_10"
                android:text="Risk"/>

            <ExpandableListView
                android:id="@+id/elRisk"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </LinearLayout>

i want to set one by one adapter when user click i don't know how to set multiple expandableList? Java File

private TestWellnessScoreBoardExpandableListAdapter mHealthaAdapter;
private TestWellnessScoreBoardExpandableListAdapter mChallengeAdapter;
private TestWellnessScoreBoardExpandableListAdapter mRiskAdapter;

private ExpandableListView elHealth;
private ExpandableListView elChallenge;
private ExpandableListView elRisk;

// this is my click listener to set adapter
private View.OnClickListener mOnClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.tvHealthTitle:

                mHealthaAdapter = new TestWellnessScoreBoardExpandableListAdapter(getActivity(), mWellnessResult.getWellnessArrayList());
                elHealth.setAdapter(mHealthaAdapter);

                break;
            case R.id.tvChallengeTitle:
                mChallengeAdapter = new TestWellnessScoreBoardExpandableListAdapter(getActivity(), mWellnessResult.getWellnessArrayList());
                elChallenge.setAdapter(mChallengeAdapter);
                break;
            case R.id.tvRiskTitle:
                mRiskAdapter = new TestWellnessScoreBoardExpandableListAdapter(getActivity(), mWellnessResult.getWellnessArrayList());
                elRisk.setAdapter(mRiskAdapter);
                break;
        }

    }
};

Every thing is work fine but view not showing showing in full screen i want to show view in full screen not in small part but its not showing in full screen

Crenellate answered 18/4, 2018 at 4:9 Comment(10)
Try using NestedScrollViewCouple
thedeveloperworldisyours.com/android/…Couple
@VishvaDave NestedScrollView not working i already tryCrenellate
@VishvaDave thanx for linkCrenellate
Yes i just checked that listview is also scrollable content so if you want to use it in scrollview you need to messure some height like the given link thedeveloperworldisyours.com/android/…Couple
@VishvaDave its working fine thank you very muchCrenellate
What you need is #17772848Headmistress
"I want three Expandablelistview in single screen not using setListViewHeight because I have nested Expandablelistview in one Expandablelistview" -- I would not expect you to have much luck with this. I recommend having one RecyclerView, using some suitable expandable-item library, to allow you to have your three collections be managed by a single widget.Longevous
Have you tried changing your first LinearLayout height to match_parent?Houchens
Use this library: github.com/davideas/FlexibleAdapterCumbrous
C
0

try this:

xml code:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_expandable_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

<LinearLayout
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">


         <ExpandableListView
        android:id="@+id/activity_expandable_list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"/>

           </LinearLayout>
           </ScrollView>

java class

mListView = (ExpandableListView) findViewById(R.id.activity_expandable_list_view);
    MyExpandableListAdapter adapter = new MyExpandableListAdapter(this,
            mGroups);
    mListView.setAdapter(adapter);
    mListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView parent, View v,
                                    int groupPosition, long id) {
            setListViewHeight(parent, groupPosition);
            return false;
        }
    });

Need this function:

private void setListViewHeight(ExpandableListView listView,
                           int group) {
ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
int totalHeight = 0;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(),
        View.MeasureSpec.EXACTLY);
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
    View groupItem = listAdapter.getGroupView(i, false, null, listView);
    groupItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);

    totalHeight += groupItem.getMeasuredHeight();

    if (((listView.isGroupExpanded(i)) && (i != group))
            || ((!listView.isGroupExpanded(i)) && (i == group))) {
        for (int j = 0; j < listAdapter.getChildrenCount(i); j++) {
            View listItem = listAdapter.getChildView(i, j, false, null,
                    listView);
            listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);

            totalHeight += listItem.getMeasuredHeight();

        }
    }
}

ViewGroup.LayoutParams params = listView.getLayoutParams();
int height = totalHeight
        + (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
if (height < 10)
    height = 200;
params.height = height;
listView.setLayoutParams(params);
listView.requestLayout();

}

Coyotillo answered 18/4, 2018 at 5:0 Comment(0)
M
0

You can not use scrollable view inside scroll view, other else you will get hight issue for child scrollable view.

Two ways to use ExpandableListView inside scroll view.

1.Create custom Non-scrollable Expandable view:

public class CustomExpandableListView extends ExpandableListView {

            public CustomExpandableListView(Context context) {
                super(context);
            }

            public CustomExpandableListView(Context context, AttributeSet attrs) {
                super(context, attrs);
            }

            public CustomExpandableListView(Context context, AttributeSet attrs, int defStyle) {
                super(context, attrs, defStyle);
            }

            @Override
            public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
                        Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
                super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
                ViewGroup.LayoutParams params = getLayoutParams();
                params.height = getMeasuredHeight();
            }
        }

Your XML:

     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context=".fragments.FragmentTestWellnessScoreBoard">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">


    <LinearLayout
        android:id="@+id/llHealth"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/tvHealthTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textStyle="bold"
            android:layout_margin="@dimen/margin_10"
            android:text="Health"/>

        <com.yourpkg.CustomExpandableListView
            android:id="@+id/elHealth"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>


    <LinearLayout
        android:id="@+id/llChallenge"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/tvChallengeTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textStyle="bold"
            android:layout_margin="@dimen/margin_10"
            android:text="Challenge"/>

        <com.yourpkg.CustomExpandableListView
            android:id="@+id/elChallenge"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>


    <LinearLayout
        android:id="@+id/llRisk"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/tvRiskTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:textStyle="bold"
            android:layout_margin="@dimen/margin_10"
            android:text="Risk"/>

        <com.yourpkg.CustomExpandableListView
            android:id="@+id/elRisk"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </LinearLayout>

</LinearLayout>
  1. Specify hard code hight to all ExpandableListViews which you wanted to use inside scroll view.

      <ExpandableListView               
            android:layout_width="match_parent"
            android:layout_height="200dp" />
    
Midiron answered 11/5, 2018 at 12:17 Comment(1)
Does the first way work correctly for 4 level expandable Listview ??Kite
S
0

try the below changes i have done in your xml design :

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="3">


        <LinearLayout
            android:id="@+id/llHealth"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tvHealthTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/margin_10"
                android:gravity="center"
                android:text="Health"
                android:textStyle="bold" />

            <ExpandableListView
                android:id="@+id/elHealth"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </LinearLayout>


        <LinearLayout
            android:id="@+id/llChallenge"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tvChallengeTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/margin_10"
                android:gravity="center"
                android:text="Challenge"
                android:textStyle="bold" />

            <ExpandableListView
                android:id="@+id/elChallenge"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>


        <LinearLayout
            android:id="@+id/llRisk"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:id="@+id/tvRiskTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/margin_10"
                android:gravity="center"
                android:text="Risk"
                android:textStyle="bold" />

            <ExpandableListView
                android:id="@+id/elRisk"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </LinearLayout>
</ScrollView>
Starknaked answered 12/5, 2018 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.