tags:

views:

407

answers:

1

A button on our screen causes an activity to be shown that has a "dialog" theme. We are having an issue were if you click the button quickly twice in a row, the dialog activity is opened twice.

Typically I would expect that when a new activity is started, the underlying activity is immediately stopped, and thus accepts no further input.

However, since the dialog themed activity does not take over the whole screen, I think the underlying activity is only paused, not stopped and thus the buttons are still accessible.

Which brings me to my question... Is there a way to force the dialog themed activity into a modal state where the user can't click the buttons on the activity below?

I could probably manually accomplish this by disabling everything in onPause, and reenabling it in onResume, but this seems like a lot of work! Anyone have an easier solution?

A: 

Along the lines of disabling things (which seens hacky and wrong), but if there isn't a real solution. The disabling could be done with a simple return in the button click event. As long as you reset the 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
        }
    });
}
sadboy
Thanks for the suggestion. That would indeed work, I'm hoping for a solution that doesn't involve custom code on every touchable item though..
Mayra