Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should one use android:clickable?

Tags:

When should we use android:clickable in XML? Should we ever?
Is there any difference between such XML declaration and in-code declaration myButton.setOnClickListener? I have read the documentation, but I could not find out when and why should I ever use this attribute.

PS. I was implementing an ad SDK and found that their developers were using android:clickable with WebView and I was intrigued why did they use it.

like image 479
sandalone Avatar asked Oct 19 '11 06:10

sandalone


People also ask

How to set button not clickable android?

Certain View types, like Button , are denoted as clickable by default. In your app, if the View is not clickable, or does not perform an action when clicked, remove its OnClickListener or set android:clickable="false" . In this way, you tell accessibility services to consider the View not clickable.

What does findViewById return?

findViewById returns an instance of View , which is then cast to the target class. All good so far. To setup the view, findViewById constructs an AttributeSet from the parameters in the associated XML declaration which it passes to the constructor of View . We then cast the View instance to Button .

What is the purpose of the Activity_main XML file in the project you created?

Choose as many answers as you see fit. What is the purpose of the activity_main. xml file in the project you created? It provides the theme settings for your app.

What is a view Android studio?

View is a basic building block of UI (User Interface) in android. A view is a small rectangular box that responds to user inputs. Eg: EditText, Button, CheckBox, etc. ViewGroup is an invisible container of other views (child views) and other ViewGroup. Eg: LinearLayout is a ViewGroup that can contain other views in it.


1 Answers

As the documentation states, and as far as I know :

clickable - Defines whether this view reacts to click events. Must be a boolean value, either "true" or "false".

So for example if you just declare a Webview or View in your layout.xml and try to set an OnClickListener on this views the OnClick event won't be fired unless you specify the attribute :

  android:clickable=true
like image 137
Ovidiu Latcu Avatar answered Oct 24 '22 02:10

Ovidiu Latcu