Search code examples
androidinvisible

Android: Invisible objects still clickable


I have an activity that has buttons and images that can appear and disappear depending on user interactions.

What I am finding is that objects at the back, which have been set to invisible, are still triggering clicks, sort of. They are not processing the code related to being clicked, but they sort of momentarily reappear, and then disappear again instantly when clicked on.

They also appear to be interfering somewhat with buttons laid over the top of them. These buttons become very fiddly and difficult to click at times, when there is an invisible object behind them.

I am using simply:

object.setVisibility(View.VISIBLE);

And:

object.setVisibility(View.INVISIBLE);

To make my items appear and disappear. Is this not what I should be doing?

EDIT:

People keep asking me for the exact same code that they are giving me. This is the code I have been given, and that I am using currently.

        btnLifePlus5.setVisibility(View.GONE);
        btnLifePlus5.setFocusableInTouchMode(false);
        txtLifePlus5.setVisibility(View.GONE);
        txtLifePlus5.setFocusableInTouchMode(false);
        btnLifePlus1.setVisibility(View.GONE);
        btnLifePlus1.setFocusableInTouchMode(false);
        txtLifePlus1.setVisibility(View.GONE);
        txtLifePlus1.setFocusableInTouchMode(false);
        btnLifeMinus5.setVisibility(View.GONE);
        btnLifeMinus5.setFocusableInTouchMode(false);
        txtLifeMinus5.setVisibility(View.GONE);
        txtLifeMinus5.setFocusableInTouchMode(false);
        btnLifeMinus1.setVisibility(View.GONE);
        btnLifeMinus1.setFocusableInTouchMode(false);
        txtLifeMinus1.setVisibility(View.GONE);
        txtLifeMinus1.setFocusableInTouchMode(false);

This makes no difference to just setting them as invisible.


Solution

  • The only way I managed to solve this ridiculous issue was to create a sort of view panel that sits between the objects in my activity. This view panel is the size of the screen, uses the same colour background, and starts invisible.

    Normally, I make object A disappear, and make object B appear. When I click the space previously occupied by object A, it momentarily flashes back onto the screen and then disappears again. It looks terrible. Subsequent clicks do not reproduce this bug until the next time I make object A disappear.

    The fix is to make object A disappear, make the new view panel visible on top of it, and then make object B appear on top of the view panel. So the panel acts as a sort of barrier between the hidden object, and user interactions. The user is not aware that this view panel even exists, as it blends in to the standard background, but when I now click the space where object A would be, it now no longer flashes back onto the screen momentarily. While this is a poor solution to have to use, this OS is bugged and I am left with no choice.

    My activity now looks as though it is perfectly stable and working perfectly. I don't like it, but it works.

    Thanks a lot, google.