如何在scrollview android中使用多个expandablelistview?

如何在scrollview android中使用多个expandablelistview?,第1张

概述我想在单个屏幕上设置3个expandablelistview我想添加多个expandablelistview XmlLayout //this is my scorllview<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android. 我想在单个屏幕上设置3个expandableListvIEw我想添加多个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>

我想在用户点击时设置逐个适配器我不知道如何设置多个expandableList?
Java文件

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 adapterprivate 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;        }    }};

每件事都很好,但看不到全屏显示

但它没有全屏显示

解决方法 试试这个:

xml代码:

<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类

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

需要这个功能:

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

}

总结

以上是内存溢出为你收集整理的如何在scrollview android中使用多个expandablelistview?全部内容,希望文章能够帮你解决如何在scrollview android中使用多个expandablelistview?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1138409.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存