Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExpandableListview Group Indicator Problem

I have changed the group indicators for my expandable list view using the code snippets below.

However, the group indicators appear shrinked and I cant seem to figure why.

The expandablelistview is inside a navigation drawer.

Code and snapshot provided.

Thanks in advance.

Code To Move indicator to right:

expListView = (ExpandableListView) getActivity().findViewById(
            android.R.id.list);
    DisplayMetrics metrics = new DisplayMetrics();
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels; 
    expListView.setIndicatorBounds(width - UIUtils.getPxFromDp(getActivity(), 40), width - UIUtils.getPxFromDp(getActivity(),20));   

Code to change indicator

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">            
       <item android:drawable="@drawable/ic_action_navigation_expand_black" android:state_empty="true">  </item>            
       <item android:drawable="@drawable/ic_action_navigation_collapse_black" android:state_expanded="true"></item>                
       <item android:drawable="@drawable/ic_action_navigation_expand_black"></item>
 </selector>

  <android.support.v4.widget.DrawerLayout
  .....
 <ExpandableListView 
    android:id="@android:id/list"
          android:layout_width="300dp"
          android:layout_height="match_parent"
          android:layout_gravity="left"
          android:background="@android:color/white"
          style="@style/ListViewMyApplynxTheme"
          android:groupIndicator="@drawable/explist_custom_group_indicator"
          android:divider="#D3D3D3"
          android:dividerHeight="1dp"/>
 </android.support.v4.widget.DrawerLayout>

XML for Group Item which is also the same used for child item:

<?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:padding="10dp"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:contentDescription="@string/app_name"
    android:src="@drawable/ic_action_delete_black"
    android:layout_marginLeft="30dp" />

<TextView
    android:id="@+id/item"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="Menu Item"
    android:gravity="center|left"
    android:paddingLeft="10dp" />

Snapshot:

Illustration of problem

like image 671
nmvictor Avatar asked Sep 06 '25 03:09

nmvictor


1 Answers

I had the same problem.

I removed the group indicator like:

android:groupIndicator="@null"

Then I put an ImageView in the group header. In the Adapter at getGroupView(), I gave this ImageView the same functionality as a group indicator:

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

        // initialize ImageView
        ImageView imgExpandCollapse = (ImageView) convertView.findViewById(R.id.imgExpandCollapse);

        // check if GroupView is expanded and set imageview for expand/collapse-action
        if(isExpanded){
            imgExpandCollapse.setImageResource(R.drawable.ic_action_collapse);
        }
        else{
            imgExpandCollapse.setImageResource(R.drawable.ic_action_expand);
        }

        return convertView;
}
like image 137
Jasper Poppe Avatar answered Sep 07 '25 20:09

Jasper Poppe