this is my layout for the same. my issue is, the list view in it is not increase the height with item count.
when I used wrap_content a given height like 210 pixel its shows the data... when I set height as wrap_content, it is showing only one item.
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/rl_createPro_option"
android:orientation="vertical"
android:layout_marginTop="5dp"
android:visibility="gone"
android:layout_marginBottom="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please provide option-wise price:"/>
<ListView
android:layout_marginTop="5dp"
android:layout_width="match_parent"
android:id="#+id/rv_createPro"
android:layout_height="wrap_content" />
<RadioGroup
android:layout_width="match_parent"
android:id="#+id/rg_createPro"
android:layout_marginTop="5dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Option highlight??"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="yes"/>
<RadioButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="no"/>
</RadioGroup>
</LinearLayout>
please help me!!
This is because of your linearlayout with vertical orientation its keeping space for the lower views like radioGroups .Set height of listview dynamically use
public static void setListViewHeightBasedOnChildren(final ListView listView) {
listView.post(new Runnable() {
#Override
public void run() {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom();
int listWidth = listView.getMeasuredWidth();
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(
View.MeasureSpec.makeMeasureSpec(listWidth, View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
totalHeight += listItem.getMeasuredHeight();
Log.d("listItemHeight " + listItem.getMeasuredHeight(), "********");
}
Log.d("totalHeight " + totalHeight, "********");
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = (totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)));
listView.setLayoutParams(params);
listView.requestLayout();
}
});
}
I have a Listview in which I need to obtain the total height sum of all the items so that the ListView height equals that height of all the items. I tried to implement the following class to accomplish that.
public class UIUtils {
/**
* Sets ListView height dynamically based on the height of the items.
*
* #param listView to be resized
* #return true if the listView is successfully resized, false otherwise
*/
public static boolean setListViewHeightBasedOnItems(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if(listAdapter != null)
{
int numberOfItems = listAdapter.getCount();
WindowManager wm = (WindowManager) listView.getContext().getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int deviceWidth;
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
Point size = new Point();
display.getSize(size);
deviceWidth = size.x;
} else {
deviceWidth = display.getWidth();
}
int desiredWidth = View.MeasureSpec.makeMeasureSpec(deviceWidth, View.MeasureSpec.AT_MOST);
int desiredHeight = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
// Get total height of all items.
int totalItemsHeight = 0;
for(int itemPos = 0; itemPos < numberOfItems; itemPos++)
{
View item = listAdapter.getView(itemPos, null, listView);
item.measure(desiredWidth, desiredHeight);
totalItemsHeight += item.getMeasuredHeight();
}
// Get total height of all item dividers.
int totalDividersHeight = listView.getDividerHeight() * (numberOfItems - 1);
int totalPadding = listView.getPaddingBottom() + listView.getPaddingTop();
// Set list height.
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalItemsHeight + totalDividersHeight + totalPadding;
listView.setLayoutParams(params);
listView.requestLayout();
return true;
}
else
{
return false;
}
}
}
Here is how I finally make use of the class described before:
ListView list = (ListView) findViewById(R.id.bills);
BillsListViewAdapter listViewAdapter = new BillsListViewAdapter(context, R.layout.item_bill, bills);
list.setAdapter(listViewAdapter);
UIUtils.setListViewHeightBasedOnItems(list);
The mentioned class will only return a static value for all the items even though on some instances the height may vary because the text of a TextView inside the item might have two or more lines.
item_bil.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/activatedBackgroundIndicator"
android:padding="10dp"
android:weightSum="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/number"
android:layout_marginEnd="2dp"
android:textSize="12sp"/>
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="{{number}}"
android:textSize="12sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hour"
android:layout_marginStart="#dimen/activity_horizontal_margin"
android:layout_marginEnd="2dp"
android:textSize="12sp"/>
<TextView
android:id="#+id/hour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="{{hour}}"
android:textSize="12sp"/>
</LinearLayout>
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="{{name}}"
android:textSize="16sp"
android:textColor="#color/colorPrimary"
android:layout_marginBottom="5dp"
android:gravity="center_vertical"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginBottom="5dp">
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="{{address}}"
android:textStyle="bold"
android:textSize="12sp"
android:gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.1">
<TextView
android:id="#+id/amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="{{amount}}"
android:textSize="18sp"
android:gravity="right"/>
</LinearLayout>
</LinearLayout>
ListView:
<ListView
android:id="#+id/charges"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"/>
Try this code. It's working fine in my App.
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
/**
* Created by Zohaib Hassan on 5/25/2015.
*/
public class ListviewHelper {
public static void getListViewSize(ListView myListView) {
ListAdapter myListAdapter = myListView.getAdapter();
if (myListAdapter == null) {
//do nothing return null
return;
}
//set listAdapter in loop for getting final size
int totalHeight = 0;
for (int size = 0; size < myListAdapter.getCount(); size++) {
View listItem = myListAdapter.getView(size, null, myListView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
//setting listview item in adapter
ViewGroup.LayoutParams params = myListView.getLayoutParams();
View listItem = myListAdapter.getView(myListAdapter.getCount() - 1, null, myListView);
listItem.measure(0, 0);
params.height = totalHeight + 10
+ (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
myListView.setLayoutParams(params);
// print height of adapter on log
Log.i("height of listItem:", String.valueOf(totalHeight));
}
}
There is another thing that can cause problem, please have a look on that issue as well. Please make sure your Screen is at-least showing one item of your listview completely before scrolling. Otherwise some part of your last item of list will be hidden. If this is the case then you have to add a static value to the total height in "ListViewHelper" class. Let's say:
params.height = totalHeight + 10 + 100
+ (myListView.getDividerHeight() * (myListAdapter.getCount() - 1));
Hope this'll help!
I'm having some issues with setting my ListView's height.
My ListView is inside a ScrollView and it's populated with some elements. In order to have my ListView expanded I programmatically calculate the height of the elements and set the ListView height accordingly.
For some reasons it's like my measures are not correct.
Here's my ListView item layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/ic_media_play"
android:tint="#android:color/black"
android:background="#android:color/transparent"
android:padding="12dp"
/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tv_trailer_item_title"
android:textSize="22dp"
android:textColor="#000000"
android:textStyle="italic"
android:padding="12dp"
/>
</LinearLayout>
And here's my piece of code for setting the ListView height:
public void setListViewHeightBasedOnChildren(ListView listView) {
TrailersAdapter listAdapter = (TrailersAdapter) listView.getAdapter();
if (listAdapter == null) {
return;
}
int elements = listAdapter.getCount();
Log.d("AAA","Got " + elements + " elements");
if (elements>0) {
View listItem = listAdapter.getView(0, null, listView);
listItem.measure(0,0);
//get the height of a single item, multiply by the number of items and get the total height for the items
int totalHeight = listItem.getMeasuredHeight() * elements;
ViewGroup.LayoutParams params = listView.getLayoutParams();
//calculate the total height summing the height of the dividers too
params.height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getCount()-1));
//set the height
listView.setLayoutParams(params);
}
}
Heres how the Activity looks like:
The trailers should be five, but only 4 are shown (in other cases half is shown)
What am I doing wrong?
I have a ListView inside a ScrollView.
To enable the scrolling in both ListView and ScrollView I implemented this method which I got from some other question on StackOverFlow.:-
public void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.UNSPECIFIED);
int totalHeight = 0;
View view = null;
for (int i = 0; i < listAdapter.getCount(); i++) {
view = listAdapter.getView(i, view, listView);
if (i == 0)
view.setLayoutParams(new ViewGroup.LayoutParams(desiredWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
view.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += view.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
The problem is that because the ListViewHeight is already to its fullest the OnScroll Method on the ListView doesnt get called. I want to execute some code when the user scrolls ( some Asynchronous loading of images ). Is there any workaround ?
My xml file for layout :-
<ScrollView
android:padding="10dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView"
android:background="#ffffffff"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="info"
android:id="#+id/njnjj"/>
<ListView
android:id="#+id/gjghjgh"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffffff"
android:visibility="visible"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
I understand that it is not at all a good practice to have a ListView inside ScrollView, but I need a workaround.
In my app i want to make a page that have ExpandableListView and below him CheckBox.
My problem is that my ExpandableListView is too big and make the CheckBox out of the page.
On smaller screens is not visible at all.
I tried to put ExpandableListView inside scrollview but its not working.
Is there a way to make my design?
Here is my code and a screenshot.
XML code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="15sp"
android:text="In this page you can save a group of exercise under one routine."
android:textColor="#color/Black"
android:textSize="20sp" />
<ExpandableListView
android:id="#+id/instructionsExView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="15sp" >
</ExpandableListView>
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/instructionsExView"
android:layout_marginTop="15sp"
android:text="If you want to open the instruction again check 'need help?'"
android:textColor="#color/Black"
android:textSize="20sp" />
<CheckBox
android:id="#+id/checkInstructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2"
android:layout_marginTop="16dp"
android:checked="false"
android:text="dont show again when opening the page"
android:textColor="#color/Black" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Screen shot:
EDIT:
in your "onCreate" method write: "setListViewHeight(expListView)" after "expListView.setAdapter(listAdapter)" then set OnGroupClickListener for your expandable list view as below:
expListView.setOnGroupClickListener(new OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
setListViewHeight(parent, groupPosition);
return false;
}
});
used methods:
private void setListViewHeight(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
private void setListViewHeight(ExpandableListView listView,
int group) {
ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
int totalHeight = 0;
int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(),
MeasureSpec.EXACTLY);
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
View groupItem = listAdapter.getGroupView(i, false, null, listView);
groupItem.measure(desiredWidth, 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, 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();
}
now u are good to go.
Based on #Dmila Ram`s answer, I was able to do it.
In my case, I initialize and populate the ExpandableListView in the onCreate method like so:
expandableListView = (ExpandableListView) findViewById(R.id.appsMenu);
listAdapter = new ExpandableListAdapter(this, listDataHeader, listDataChild);
expandableListView.setAdapter(listAdapter);
for (int i = 0; i < listAdapter.getGroupCount(); i++)
expandableListView.expandGroup(i);
setListViewHeight(expandableListView);
expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
#Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
setListViewHeight(parent, groupPosition);
return false;
}
});
Notice that I expand each group. After that I call setListViewHeight(expandableListView);
This method is responsible for calculating the height of the ExpandableListView when it is created for first time.
Here is the code:
private void setListViewHeight(ExpandableListView listView) {
ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
int totalHeight = 0;
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
View groupView = listAdapter.getGroupView(i, true, null, listView);
groupView.measure(0, View.MeasureSpec.UNSPECIFIED);
totalHeight += groupView.getMeasuredHeight();
if (listView.isGroupExpanded(i)){
for(int j = 0; j < listAdapter.getChildrenCount(i); j++){
View listItem = listAdapter.getChildView(i, j, false, null, listView);
listItem.measure(0, View.MeasureSpec.UNSPECIFIED);
totalHeight += listItem.getMeasuredHeight();
}
}
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
It's really not necessary to have the groups expanded, instead we can just loop through the child items and add them to the calculation of the total height.
This will make all widgets in the ScrollView scrollable and it will also show the ExpandableListView properly.
Then we also need this method, to make sure that clicking on the groups will calculate the height as well:
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();
}
That's pretty much it, then it works fine, but this solution can be optimized even further.
you cant use listview inside scroll view ,so you should use scroll view and add the rows as views dynamically.
You do not need more than one RelativeLayout, because expandablelistview should be between two items (in your case), these two items are going to be the first ones with parentTop and parentBottom, the rest will be positioned playing with above/below.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/White"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="15sp"
android:text="In this page you can save a group of exercise under one routine."
android:textColor="#color/Black"
android:textSize="20sp" />
<CheckBox
android:id="#+id/checkInstructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="16dp"
android:checked="false"
android:text="dont show again when opening the page"
android:textColor="#color/Black" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/checkInstructions"
android:layout_marginTop="15sp"
android:text="If you want to open the instruction again check 'need help?'"
android:textColor="#color/Black"
android:textSize="20sp" />
<ExpandableListView
android:id="#+id/instructionsExView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_below="#id/textView1"
android:layout_marginTop="15sp" >
</ExpandableListView>
</RelativeLayout>
You can use below code to achieve this thing. I used ListViewyou can replace with ExpandableListView
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="15sp"
android:text="In this page you can save a group of exercise under one routine."
android:textColor="#color/WHITE"
android:textSize="20sp" />
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2" >
</ListView>
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15sp"
android:text="If you want to open the instruction again check 'need help?'"
android:textColor="#color/WHITE"
android:textSize="20sp" />
<CheckBox
android:id="#+id/checkInstructions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2"
android:layout_marginBottom="20dp"
android:layout_marginTop="16dp"
android:checked="false"
android:text="dont show again when opening the page"
android:textColor="#color/WHITE" />
I checked the above code with around 50 listitem value and tested on a very small display device and it works fine.
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="15sp"
android:text="In this page you can save a group of exercise under one routine."
android:textColor="#color/WHITE"
android:textSize="20sp" />
<ExpandableListView
android:id="#+id/expandableListView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2" >
</ExpandableListView>
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15sp"
android:text="If you want to open the instruction again check 'need help?'"
android:textColor="#color/WHITE"
android:textSize="20sp" />
<CheckBox
android:id="#+id/checkInstructions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2"
android:layout_marginBottom="20dp"
android:layout_marginTop="16dp"
android:checked="false"
android:text="dont show again when opening the page"
android:textColor="#color/WHITE" />
I checked with ExpandableListView and it working fine for me.