0

For example, if we set OnClick on button and also set it invisible
It still works right ? If yes, What's a real life scenario in which it would be beneficial ? If there is no use , Why does android even allow to have onClick on Invisible view and it doesn't even give warning or anything.

I am curious to know :')

Tim
  • 41,901
  • 18
  • 127
  • 145
  • 2
    Scenario: Guess where the apple is on screen and earn points! Don't want onClick on view that you can't see? Use `GONE` – Rohit5k2 Mar 22 '18 at 11:26
  • when you are developing games, you may want to do that. – Jyoti JK Mar 22 '18 at 11:27
  • 1
    Possible duplicate of [Android: Invisible objects still clickable](https://stackoverflow.com/questions/32140625/android-invisible-objects-still-clickable) – Rohit5k2 Mar 22 '18 at 11:29
  • @JyotiJK that's exactly what i thought like hidden bricks to power up in mario But i want to know how it can be helpful in apps and not games :') – Yogesh Gosavi Mar 22 '18 at 11:29
  • certainly not a duplicate. However also not great question, since only the framework designers can answer this, and it's unlikely they will – Tim Mar 22 '18 at 11:29
  • 1
    A game is an app, isn't it? Do you Android to keep two separate personalized SDK for games and apps? This question is becoming silly. – Rohit5k2 Mar 22 '18 at 11:31
  • @Rohit5k2 yes of course Game is an App i want to know for what else we can make use of Such invisible onClick views :) – Yogesh Gosavi Mar 22 '18 at 11:35
  • That would come with scenarios when you actually work on an app (or game). Wait and you will see its benefits. – Rohit5k2 Mar 22 '18 at 11:36
  • @TimCastelijns check my answer – Lucem Mar 22 '18 at 12:07
  • @Lucem ok. I downvoted it – Tim Mar 22 '18 at 12:51

2 Answers2

1

You are using android views in the wrong way. Views have three properties to alter visibility which are

  1. Visible: By default, all views are visible
  2. Invisible: The view is not visible but occupies space and resources
  3. Gone: The view is entirely out of the layout

Visisble is used to set a view from either of the other two.

Invisible is used when you want a certain button that is lying on top of another view to be clicked rather than the view. It can also be used when you want a view to occupy space but not be present for the user. This scenario might occur when using LinearLayouts with android:layoutWeight

Gone is used when you want to completely hide a view from the picture. This is common with login screens and welcome previews in apps

Lucem
  • 2,912
  • 3
  • 20
  • 33
0

Because for a View visibility and onClick are completely independent properties.

When a View is INVISIBLE as per its property it is just not shown but present in the given place, so onClick() would work on the view. In case if a view is GONE, as the view itself is not present at the expected place, onClick function wont be called.

GiridharaSPK
  • 496
  • 7
  • 17