Android: activate dialog action to be modal

A button on the screen displays an activity that has a dialogue topic. We have a problem: if you double-click the button twice, the dialog operation opens twice.

Normally, I would expect that when a new action starts, the main action will stop immediately and thus will not accept any additional input.

However, since the interactive activity does not affect the entire screen, I think that the main action is paused rather than stopped, and thus the buttons are still available.

Which brings me to my question ... Is there a way to force the thematic activity of the dialog box to be activated in a modal state when the user cannot click the buttons in the operation below?

Perhaps I could do this manually by disabling everything in onPause and re-enabling it in onResume, but that seems like a lot of work! Does anyone have an easier solution?

+3
source share
2 answers

Along the lines of disconnecting things (which seem hacked and wrong), but if there is no real solution. Disabling can be done with a simple return to the button press event. As long as you reset bool when the dialog returns or in onResume

boolean clicked;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button b = (Button)findViewById(R.id.Button01);
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (clicked)
                return;
            clicked = true;
            // show dialog
        }
    });
}
+1
source

Another solution is not to start your activity using a dialogue topic, but a standard one. In your XML for action, specify, say, a textview that spans the entire screen. However, make the textview transparent (or semi, color, or ....) and clickable.

XML "", . , , . :

<TextView android:id="@+id/ViewHider"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#aa000000"
    android:enabled="true"
    android:clickable="true"
    ></TextView>

<!-- Then put your "dialog" xmal here -->
0

Source: https://habr.com/ru/post/1732279/


All Articles