Issue
I have an ExpandableListView that I want to customize with a different view when the item is expanded. The problem is the image I have assigned to the state_expanded attribute is never shown. I've tried almost all other attribute for the state but the only one that does anything is state_pressed and it just briefly shows a different image when the state is pressed. How do I get my list_item_expanded drawable to stay shown when the item is expanded? Any ideas or help would be appreciated.
Here is my selector.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/list_item_expanded" android:state_expanded="true"></item>
<item android:drawable="@drawable/list_item"></item>
</selector>
Here is my where I style my ExpandableListView
<style name="customExpandableList" parent="@android:style/Widget.ExpandableListView">
<item name="android:groupIndicator">@null</item>
<item name="android:dividerHeight">5dp</item>
<item name="android:divider">@android:color/transparent</item>
<item name="android:listSelector">@android:color/transparent</item>
<item name="android:cacheColorHint">@android:color/transparent</item>
<item name="android:childDivider">@android:color/transparent</item>
</style>
I set the selector as a drawable in the adapter like so:
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View view, ViewGroup parent) {
if (view == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.trans_sum_row, null);
}
view.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.list_item_selector));
}
Solution
There doesn't seem to be a way to do what I was trying to do. The android:state_expanded
attribute is only applicable to the group indicator and not the ExpandableListView itself. What I ended up doing was creating one selector for the ELV and another for the group indicator like so
<style name="customExpandableList" parent="@android:style/Widget.ExpandableListView">
<item name="android:groupIndicator">@drawable/custom_group_selector</item>
<item name="android:background">@drawable/custom_elv_selector</item>
<item name="android:dividerHeight">5dp</item>
<item name="android:divider">@android:color/transparent</item>
<item name="android:listSelector">@android:color/transparent</item>
<item name="android:cacheColorHint">@android:color/transparent</item>
<item name="android:childDivider">@android:color/transparent</item>
</style>
After that I was able to get the same effect I wanted by positioning the group indicator where I wanted by using the SO solution here.
Positioning the group indicator this way hasn't proven the best solution for me because I'm seeing different results on some phones but that is a different post in itself.
Answered By - DroidT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.