Keep selected button after opening dialog which was done with an Activity

1

I have two buttons like this:

btnSurPlace.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            v.setPressed(true);

            // show interest in events resulting from ACTION_DOWN
            if (event.getAction() == MotionEvent.ACTION_DOWN) return true;

            // don't handle event unless its ACTION_UP so "doSomething()" only runs once.
            if (event.getAction() != MotionEvent.ACTION_UP) return false;

            onPlace = true;
            btnEmporter.setPressed(false);
            return true;
        }
    });

    btnEmporter.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // show interest in events resulting from ACTION_DOWN
            if (event.getAction() == MotionEvent.ACTION_DOWN) return true;

            // don't handle event unless its ACTION_UP so "doSomething()" only runs once.
            if (event.getAction() != MotionEvent.ACTION_UP) return false;

            onPlace = false;
            v.setPressed(true);
            btnSurPlace.setPressed(false);
            return true;
        }
    });

The problem is that in the activity I open a dialogue made with an Activity

<activity
        android:name=".MenuDialog"
        android:theme="@android:style/Theme.Holo.Light.Dialog.NoActionBar.MinWidth" />

When you open such Dialog, the selected button is deselected.

How can I make the button that the person selected, keep selected even after opening and closing the Dialog.

    
asked by Eduardo Ricardez 17.05.2017 в 22:44
source

1 answer

0

I find it a little weird about keeping the button "pressed" but you can do it with the property:

setPressed(true);

example:

    @Override
    public boolean onTouch(View v, MotionEvent event) {
         btn.setPressed(true);
        return true;
    }
    
answered by 17.05.2017 в 23:35