As regards to expandable list view, the group icon indicator is positioned to the left side, can I move the indicator and positioned it to the right? Thanks.
setIndicatorBounds(int, int) does not work properly for Android 4.3. They introduced a new method setIndicatorBoundsRelative(int, int) which works ok for 4.3.
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
mExpandableListView.setIndicatorBounds(myLeft, myRight);
} else {
mExpandableListView.setIndicatorBoundsRelative(myLeft, myRight);
}
}
According to ExpandableListView
's source code, the only way to move an indicator to the right side is to change its bounds using ExpandableListView.setIndicatorBounds()
method. You can calculate bound in onSizeChanged()
method, for example.
if it is in Fragment - onViewCreated()
ViewTreeObserver vto = Expnlist.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Expnlist.setIndicatorBounds(Expnlist.getMeasuredWidth() - 80, Expnlist.getMeasuredWidth());
}
});
its works for me!. Cheers!
First you have to remove group indicator from your xml
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/nav_header_height"
android:background="@android:color/white"
android:dividerHeight="0dp"
android:focusable="false"
android:groupIndicator="@null" />
then do as follows in your custom 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);
}}