Hiding group indicator in Expandable List view - android

I want to hide the group expanded/collapsed indicator in n expandable list view in all of my list elements and instead show an image in place of the indicator. I've made the indicator color transparent using this:
android:groupIndicator="#android:color/transparent
But that won't let me place the image where the indicator used to be so I need a new way to do it.

Implement your own BaseExpandableListAdapter:
public class MyExpandableListAdapter extends BaseExpandableListAdapter {
...
#Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(mContext);
View rowView = inflater.inflate(R.layout.list_group_item, null);
return rowView;
}
...
}
list_group_item should contain the desired group indicator image. And don't forget to disable native indication:
expandableListView.setGroupIndicator(null);

you need set android:groupIndicator="#null"

Related

Group Indicator is not coming in the right side of Expandable List view

Group Indicator is not coming in the right side of Expandable List view in android Even if I have applied all the given solution for it but its not working
In the xml file
ExpandableListView
android:groupIndicator="#null"
In adapter
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (isExpanded) {
groupHolder.img.setImageResource(R.drawable.group_down);
} else {
groupHolder.img.setImageResource(R.drawable.group_up);
}
}
You have to use custom image to achieve this.

Android expendable listview with same background either opened or not

I am trying to create an expendable listview which has same sort of background when it expends or not. i am attaching the picture too. I tried it with backgrounds but failed.
<ExpandableListView
android:id="#+id/expandableListView_tracks"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="-10dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/my_toolbarX" >
</ExpandableListView>
Thanks in advance
You can change the background of group if expanded or not expanded using your Adapter code like this:
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = minflater.inflate(R.layout.grouprow, null);
}
......
if (isExpanded){
// your group is expanded change background of main layout of your group row
}else{
// your group is not expanded change background of main layout of your group row
}
........
return convertView;
}
define id to your row_group main Layout and change the background of this layout.

Android how to use different layouts for each listview item

In my application I can only use the same layout for each listview item in each row. This is not what I want for my application and I would like to have a different layout for each of the listview items.
As an example of what I would like to achieve please see the screenshot below.
You can do it via android Listview BaseAdapter. In BaseAdapter getView method, you can added code like this.
public View getView(final int position, View convertView, ViewGroup parent) {
if(item1 or your condition)
{
convertView=inflater.inflate(R.layout.from_right_row.xml, parent, false);
}else if(item2 or your condition) {
convertView=inflater.inflate(R.layout.from_left_row.xml, parent, false);
}
return convertView;
}

How do I remove the arrow for a particular group (row) in an ExpandableListView

By default every group has a downward arrow that indicates to the user that the item can be expanded. However, I have one group that has no children; thus, I would like the arrow to not show on this item.
According to the documentation:
public void setGroupIndicator (Drawable groupIndicator)
Sets the indicator to be drawn next to a group.
Parameters
groupIndicator The drawable to be used as an indicator. If the group is empty, the state state_empty will be set. If the group is expanded, the state state_expanded will be set.
So hypothetically, this should already do the right thing... But, if you are using your own custom ExpandableListAdapter, with TextViews for example, you can use the following code:
// in your main file where the List is defined:
mExpandableList.setGroupIndicator(null); // this will remove the indicator
Then in your custom adapter you could do the following:
#Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
View v;
...
// code to retrieve convertView or inflate new one and assign to v
...
TextView tv = ((TextView) v);
int iconId; // assume we have an icon we want to have on the left of each group
int expandableGroupResId;
if (getChildrenCount(groupPosition) > 0) {
if (isExpanded) expandableGroupResId = R.drawable.expander_ic_maximized;
else expandableGroupResId = R.drawable.expander_ic_minimized;
}
tv.setCompoundDrawablesWithIntrinsicBounds(iconId, 0, expandableGroupResId, 0);
}

Android ExpandableListView GroupIndicator gravity

How to change default GroupIndicator gravity of Android ExpandableListView?
Set android:groupIndicator="#null" in "expandablelist"
Add ImageView in "groupview" xml
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
ImageView mGroupIndicator=(ImageView)convertView.findViewById(R.id.mGroupimage);
if(isExpanded){
mGroupIndicator.setImageResource(R.drawable.expanded);
}else{
mGroupIndicator.setImageResource(R.drawable.collapsed);
}
}
You can't change the default one.. but if you are implementing custom Adapter .. you can put a checkBox with group indicator background and position it where ever you want..

Categories

Resources