What is better solution to implement such layout:
I've tryid:
listview with negative divider (bad solution when rows need to have
different height)
scroll view with relativelayout (bad solution
because of memory consumption)
two listviews scrolling
simultaniously (very bad)
Create custom layout for listview items.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2" >
<LinearLayout
android:id="#+id/evenSideLayout"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="25dp"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/oddSideLayout"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_marginTop="0dp"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
Now in your custom Adapter... Manage layouts visibility. like
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
convertView = inflater.inflate(R.layout.item_option_layout, parent,
false);
LinearLayout oddLayout = (LinearLayout) convertView.findViewById(R.id.oddLayout);
LinearLayout evenLayout = (LinearLayout) convertView.findViewById(R.id.evenLayout);
if(position%2==0)
{
evenLayout.setVisibility(View.VISIBLE);
oddLayout.setVisibility(View.GONE);
}
else
{
evenLayout.setVisibility(View.GONE);
oddLayout.setVisibility(View.VISIBLE);
}
return convertView;
}
Related
This is my code for how each row looks.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="120dp"
android:id="#+id/recipe_container"
android:layout_margin="12dp"
android:background="#f1f1f1">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/recipe_name_text_view"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical"
android:textSize="32sp"
android:text="DUMMY TEXT"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="#+id/recipe_time_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DUMMY TEXT"/>
<TextView
android:id="#+id/recipe_difficulty_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DUMMY TEXT"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/recipe_thumbnail_image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/sladice"/>
</LinearLayout>
As you can see I have margin set, if I check preview it is also shown.
I populated with inflate this listivew.
This is activity_sladice.xml.
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/recipe_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.android.recepti.Sladice"
android:background="#color/colorPrimary">
</ListView>
Now each row is together, there is no spacing between left, right, bottom , top.
If I add margin or padding to listview it only works on the entire list, not on each row.
How to do it? I know I can add divider between each row but I also want spacing right and left.
This is getView method from custom adapter.
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View recipeView = convertView;
ReceptThumbnail recipe = getItem(position);
// Inflate view if to be inflated
if (recipeView == null) {
recipeView = LayoutInflater.from(getContext()).inflate(R.layout.recipe_item, parent, false);
}
TextView recipeName = (TextView) recipeView.findViewById(R.id.recipe_name_text_view);
recipeName.setText(recipe.getName());
TextView recipeTime = (TextView) recipeView.findViewById(R.id.recipe_time_text_view);
recipeTime.setText(recipe.getTime());
TextView recipeDifficulty = (TextView) recipeView.findViewById(R.id.recipe_difficulty_text_view);
recipeDifficulty.setText(recipe.getDifficulty());
ImageView recipeImage = (ImageView) recipeView.findViewById(R.id.recipe_thumbnail_image_view);
recipeImage.setImageResource(recipe.getImageResourceID());
}
If you want to add margins to the ListView, add margns to the listview.
If you want to add margins to the items, add margins to the items.
It is simple.
However, I suggest you to use ConstraintLAyout. And RecyclerView instead of ListView.
Try using padding in the LinearLayout, and create another LinearLayout as a child of the original, and move the background attribute to it.
try setting margin programmatically in getView method using below method.
public static void setMarginLeft(View v, int left) {
ViewGroup.MarginLayoutParams params =
(ViewGroup.MarginLayoutParams)v.getLayoutParams();
params.setMargins(left, params.topMargin,
params.rightMargin, params.bottomMargin);
}
As shown in the image, I am able to render the view. But the onChildClick event of Expandable view is not getting triggered.
Also the touch event in the adapter is not responding. My layout details are mentioned below.
The full source code for this can be found in here.
main_activity.xml
<ExpandableListView
android:id="#+id/list_brands"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="#null"
android:groupIndicator="#null"
android:dividerHeight="5dp" />
item_parent.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:gravity="center_vertical">
<TextView
android:id="#+id/text_brand"
android:textSize="18dp"
android:text="Text"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/image_indicator"
android:src="#drawable/ic_keyboard_arrow_down_black_18dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
item_group_child.xml
<android.support.v7.widget.RecyclerViewxmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mobiles"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
item_child.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp">
<ImageView
android:id="#+id/image_mobile"
android:layout_width="70dp"
android:adjustViewBounds="true"
android:layout_height="120dp" />
<TextView
android:id="#+id/text_mobile_model"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
<TextView
android:id="#+id/text_mobile_price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" />
</LinearLayout>
**My Solution : **
Touch events are directly passed to the UI Elements of the View holder in the Recycler List view. But to give the touch event to the whole layout I have added the transparent button on top of child_item layout and added a click listener. Following is the updated child_item.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent" >
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/dummy_click"
android:background="#android:color/transparent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:padding="10dp"
android:background="#color/colorGrey"
>
<ImageView
android:id="#+id/img_subcategory"
android:layout_gravity="center"
android:src="#mipmap/ic_launcher"
android:layout_marginTop="10dp"
android:layout_width="180dp"
android:layout_height="90dp"
android:scaleType="fitXY"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sub Category"
android:textColor="#color/colorWhite"
android:layout_marginTop="10dp"
android:layout_marginBottom="5dp"
android:gravity="center"
android:id="#+id/txt_subcategory"
android:textSize="#dimen/app_text_title"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
Theory
ExpandableListView, child click sample:
for click on child, you can handle this way.
getExpandableListView().setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// your code...
}
});
Expandable RecyclerView, useful library and easy item click support:
This blog post by Hugo shows an alternative way without listeners:
http://www.littlerobots.nl/blog/Handle-Android-RecyclerView-Clicks/
It comes down to adding these lines:
ItemClickSupport.addTo(mRecyclerView).setOnItemClickListener(new ItemClickSupport.OnItemClickListener() {
#Override
public void onItemClicked(RecyclerView recyclerView, int position, View v) {
// do it
}
});
When using this class:
public class ItemClickSupport {...}
And this value in ids.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="item_click_support" type="id" />
</resources>
Why doesn't RecyclerView have onItemClickListener()? And how RecyclerView is different from Listview?
Since the introduction of ListView, onItemClickListener has been
problematic. The moment you have a click listener for any of the
internal elements the callback would not be triggered, but it wasn't
notified or well documented (if at all) so there was a lot of
confusion and SO questions about it.
OnItemClickListener doesn't work with ListView item containing button
Just add this line into the item views instead of listView itself
android:focusable="false"
Check more detail about this from: Android custom ListView unable to click on items
Practice
#Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildHolder childHolder = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.item_group_child, parent, false);
childHolder = new ChildHolder();
// Fix listview onclicklistener issue: inner views can not be focusable
childHolder.YOUR_INNER_BUTTON = (YOUR_BUTTON_TYPE) convertView.findViewById(R.id.YOUR_BUTTON_ID);
childHolder.YOUR_INNER_BUTTON.setFocusable(false);
convertView.setTag(childHolder);
}
else {
childHolder = (ChildHolder) convertView.getTag();
}
childHolder.horizontalListView = (RecyclerView) convertView.findViewById(R.id.mobiles);
LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
childHolder.horizontalListView.setLayoutManager(layoutManager);
MobileAdapter horizontalListAdapter = new MobileAdapter(context, brands.get(groupPosition).mobiles);
childHolder.horizontalListView.setAdapter(horizontalListAdapter);
return convertView;
}
Added two lines to your code based on my legacy code:
// Creates a ViewHolder and store references to the children views (collapsed)
holder = new ViewHolderChildren();
holder.textLine = (TextView) convertView.findViewById(R.id.usersTextLine);
holder.subtextLine = (TextView) convertView.findViewById(R.id.usersSubtextLine);
holder.iconLine = (ImageView) convertView.findViewById(R.id.usersIconLine);
holder.buttonLine = (ImageButton) convertView.findViewById(R.id.usersButtonLine);
holder.infoLine = (TextView) convertView.findViewById(R.id.usersInfoLine);
holder.infoLine.setVisibility(TextView.GONE);
holder.userprofileButton = (ImageButton) convertView.findViewById(R.id.usersUserprofileBtn);
holder.buttonLine.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// if gone, set visible and arrow up image
if (holder.infoLine.getVisibility() == TextView.GONE) {
holder.infoLine.setVisibility(TextView.VISIBLE);
holder.buttonLine.setImageLevel(1);
}
// if visible, set gone and arrow down image
else {
holder.infoLine.setVisibility(TextView.GONE);
holder.buttonLine.setImageLevel(0);
}
}
});
//fixed listview onclicklistener bug: inner views can not be focusable
holder.buttonLine.setFocusable(false);
convertView.setTag(holder);
I'm trying to create an adapter for a listview, which contains two elements in a same row.
The LayoutFile got two linear LinearLayouts Layout Image with two images and name
The adapter only fill the first LinearLayout data, and don't show the second LinearLayout.
Someone could help me? Thanks in advance !
XML File:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/imageViewItem"
android:layout_width="match_parent"
android:layout_height="175dp"
android:src="#drawable/icon" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left">
<TextView
android:id="#+id/textViewTitleItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Title"
android:gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right">
<TextView
android:id="#+id/textViewPriceItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Price"
android:gravity="center" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
It is only a View, I want to duplicate it in the same row.
Below the adapter:
public ItemAdapter(Activity activity, int layoutResourceId)
{
this.activity = activity;
this.layoutResourceId = layoutResourceId;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var row = convertView;
var currentItem = this[position];
TextView txtViewTitle;
TextView txtViewPrice;
ImageView imgViewItem;
if (row == null)
{
var inflater = activity.LayoutInflater;
row = inflater.Inflate(layoutResourceId, parent, false);
txtViewTitle = row.FindViewById<TextView>(Resource.Id.textViewTitleItem);
txtViewPrice = row.FindViewById<TextView>(Resource.Id.textViewPriceItem);
imgViewItem = row.FindViewById<ImageView>(Resource.Id.imageViewItem);
} else
txtViewTitle = row.FindViewById<TextView>(Resource.Id.textViewTitleItem);
txtViewPrice = row.FindViewById<TextView>(Resource.Id.textViewPriceItem);
imgViewItem = row.FindViewById<ImageView>(Resource.Id.imageViewItem);
txtViewTitle.Text = currentItem.Title;
txtViewPrice.Text = Convert.ToString(currentItem.Price);
return row;
}
It seems that you didn't provide orientation to your parent LinearLayout. By default it is horizontal.
That's why its showing only top layout content.
You need to set it as vertical to show the entire content in your list.
android:orientation="vertical"
I want to implement a layout which resembles Bank's PassBook. So I thought should I implement table layout inside a list view.
Here is a sample passbook example.
DATE PARTICULARS DEBIT CREDIT BALANCE
12/06/2014 Withdraw 200 10000
11/06/2014 Deposit 200 10200
create xml layout like below
<LinearLayout 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"
tools:context=".MainActivity"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:id="#+id/date"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/hello_world" />
<TextView
android:id="#+id/action_type"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:gravity="center"
android:layout_weight="1"/>
<TextView
android:id="#+id/amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:gravity="center"
android:layout_weight="1"/>
</LinearLayout>
use this layout as list item for your ListView.
Use an ArrayAdapter for your ListView.
In there, you can inflate the Layout for the items of the list, be it a TableLayout, or something other.
private class MyListAdapter extends ArrayAdapter<SomeObject> {
public MyListAdapter(Context context, int resource, List<SomeObject> someObjectList) {
super(context, resource, someObjectList);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
//view recycling
if (convertView == null) {
// inflate the single row with whatever layout you like
view = getLayoutInflater().inflate(R.layout.table_row, parent, false);
} else {
view = convertView;
}
SomeObject item = getItem(position);
//fill the view with data
TextView date = (TextView) view.findViewById(R.id.date);
date.setText(item.getDate());
...
return view;
}
...
}
Here's a little to read about ListViews and ArrayAdapter:
https://github.com/thecodepath/android_guides/wiki/Using-an-ArrayAdapter-with-ListView1
I want to put divider only between parent elements. When i set
android:divider="#drawable/divider" android creates divider between parent elements, but creates divider between child elements too. When i add android:childDivider="#color/transparent" android removes the divider between child elements, but the free space between them remains. Why?
I have tried to android:dividerHeight="0dp" but nothing happened.
At all i want to set divider between parent elements, but i do not want any divider or empty space between child elements.
any ideas how to do that??
In order to remove dividers just from the child views and not between the parents in the expandable list:
add android:childDivider="#00000000" in the ExapandableListView attributes in XML:
<ExpandableListView
android:id="#+id/elv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:childDivider="#00000000" />
Refer this page for more information
Give Divider color and its height (dividers will be visible when groups are collapsed)
<ExpandableListView
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="#color/color_black"
android:dividerHeight="1dp"
android:groupIndicator="#null" />
The trick is to create an extra view for collapse group layout and last child layout.
collapse_group.xml:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"/>
<!-- this is the extra view-->
<View
android:layout_width="fill_parent"
android:layout_height="10dp"
android:background="#android:color/transparent"/>
</LinearLayout>
expanded_group.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"/>
<!-- no extra view-->
</LinearLayout>
And apply the same technique to the child view, for the last child view insert the extra view
What I did was to set the ExpandableListView's divider to 0 and then insert "divider" groups into it's ExpandableListAdapter:
// To get dividers between the groups we add 'divider views' as if they were
// themselves groups.
public int getGroupCount() {
// Actual groups are at even groupPositions, dividers at odd
return (this.data.size() * 2) - 1;
}
public long getGroupId(int groupPosition) {
if(groupPosition % 2 != 0) return R.id.divider;
else return R.id.group;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if(groupPosition % 2 != 0) {
View divider = convertView;
if(divider == null || divider.getId() != R.id.divider) {
divider = this.inflater.inflate(R.layout.divider, null);
}
return divider;
}
View group = convertView;
if(group == null || group.getId() != R.id.group) {
group = this.inflater.inflate(R.layout.group, null);
}
return group;
}
expListView.setDividerHeight(10);
expListView.setChildDivider(getResources().getDrawable(
android.R.color.white));
If you want to remove child divider only, One simple trick is You can create a drawable with same color as of your child item's background color. Then set it as child divider.
ShapeDrawable sd1 = new ShapeDrawable(new RectShape());
sd1.getPaint().setColor(YOUR CHILD ITEM BACKGROUND COLOR);
mExpListView.setChildDivider(sd1);
Or using xml:
android:childDivider="#color/child_bg_color"
If you want to have divider between parent element of the ExpandableListView (Header) and don't want to have divider between children and parent , which is obviously the most natural case, then you have to do following:
In your parent xml file add one View at the bottom of the layout with divider height and divider color that you need.
Example:
Do same in the child xml file. Add one View at the bottom of the layout with divider height and divider color that you need. Make sure divider color and height are same like in parent xml.
Into your ExpandableListView Adapter method
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent)
manage the state of the View divider like this:
Example:
if(isExpanded){
headerDividerView.setBackgroundColor(ContextCompat.getColor(context,R.color.darker_grey));
}else{
headerDividerView.setBackgroundColor(ContextCompat.getColor(context,android.R.color.transparent));
}
BTW : In my case R.color.darker_grey is background color of the parent
Remove from your ExpandableListView xml all dividers and dividers height. Make ExpandableListView to not have dividers and divider height.
You can use attrs like this :
android:groupIndicator="#null"
android:childIndicator="#null"
android:divider="#null"
android:dividerHeight="0dp"
I solved it by adding two views one to header and other to child item like shown below.
Header.xml
<?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="wrap_content">
<RelativeLayout
android:id="#+id/rl_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/square_box"
android:padding="#dimen/padding_10">
<ImageView
android:id="#+id/expandableIndicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_downarrow" />
</RelativeLayout>
<View
android:id="#+id/view_hidden"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_below="#+id/rl_header"
android:background="#android:color/transparent" />
</RelativeLayout>
child.xml
<?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="wrap_content">
<RelativeLayout
android:id="#+id/rl_childView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/square_box"
android:padding="#dimen/padding_10">
<TextView
android:id="#+id/tv_startDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:gravity="left"
android:paddingTop="#dimen/padding_5"
android:paddingBottom="#dimen/padding_5"
android:text="Start Date \nSep. 23, 2019"
android:textSize="#dimen/text_16" />
<ImageView
android:id="#+id/iv_arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="#drawable/right_arrow" />
</RelativeLayout>
<View
android:id="#+id/view_hidden"
android:layout_width="match_parent"
android:layout_height="10dp"
android:layout_below="#+id/rl_childView"
android:background="#android:color/transparent" />
</RelativeLayout>
Now add this code to your Adapter class. The idea is to show/hide the View when group is expanded/collapsed, show on child last item.
#Override
public View getGroupView(int listPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
String listTitle = (String) getGroup(listPosition);
String listCount = "(" + getChildrenCount(listPosition) + ")";
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater)
this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.expandable_header, null);
}
View view_hidden = convertView.findViewById(R.id.view_hidden);
if (isExpanded) {
view_hidden.setVisibility(View.GONE);
} else {
view_hidden.setVisibility(View.VISIBLE);
}
return convertView;
}
#Override
public View getChildView(int listPosition, final int expandedListPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final Medication medication = (Medication) getChild(listPosition,
expandedListPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater)
this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.expandable_item, null);
}
View view_hidden = convertView.findViewById(R.id.view_hidden);
if (isLastChild) {
view_hidden.setVisibility(View.VISIBLE);
} else {
view_hidden.setVisibility(View.GONE);
}
return convertView;
}
set like this android:divider="#null" no divider for parents android:divider="2dp" set divider for parents
<ExpandableListView
android:id="#+id/expandable_list"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:divider="2dp"
android:groupIndicator="#drawable/group_indicator" />