Somk
Somk

Reputation: 12047

Expandable Listview Can You Move a Custom Icon ( indicator )?

I know it is possible to create a custom group indicator in an expandable listview. I also know that you can position the default group indicator by using setIndicatorBound(). What I have not seen and been unable to achieve myself is to combine these two effects.

Does anyone know of any actual proof that these are able to be done in conjunction?

At the moment I can create a custom indicator and move it. But when I use setIndicatorBounds it always moves to half way off the screen on the right. Check this Related Post

My question is can you actually achieve this? Is there proof anywhere as I have found none.

Upvotes: 1

Views: 2754

Answers (1)

peter.bartos
peter.bartos

Reputation: 12045

I achieved this using following tutorial: http://android-adda.blogspot.com/2011/06/custom-expandable-listview.html

The key is this code:

    DisplayMetrics metrics = new DisplayMetrics();
    ExpandableListView expList = getExpandableListView();

    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels;
    //this code for adjusting the group indicator into right side of the view
    expList.setIndicatorBounds(width - GetDipsFromPixel(50), width - 

    public int GetDipsFromPixel(float pixels)
    {
        // Get the screen's density scale
        final float scale = getResources().getDisplayMetrics().density;
        // Convert the dps to pixels, based on density scale
        return (int) (pixels * scale + 0.5f);
    }

Upvotes: 7

Related Questions