How to make a button unclickable, except after checking a radio button?
If the button is called myButton try using
myButton.setEnabled(false);
Then you can add some type of listener to your radio button and in that listener add
myButton.setEnabled(true);
Also, you can check out the android:clickable attribute in xml.
Related
I have menu button in screen,i set setfocusableInTouchMode and onclick for menu Button.If i click the menu button it getting focused and second click only getting fired.I want to do both operation at a time.
call RequestFocus on your Button followed by performClick() this will focus and also fire click event on your Button .
I have a scenario that we should have a single choice mode radio button in listview. when I click on the radiobutton it should go to enable state. when I click on the whole item then it should redirect to the new activity.
You can simply create a composite view for this. Due to the way the native radiobutton is built you can't differentiate between click on the circle or click on the item.
You can have a radiobutton without text associated to a textview or whatever view you may need. Then you simply listen to clicks on the textview or the radiobutton.
For the radiobutton you can keep the default behavior and for the textview you have a button-like onClickListener.
**I am using custom listview when i placing the button in custome view it is disabling the item touch or itemlongpress listener ...
How to use button click and listview touch simultaneously
The Problem here is , Listview having button as a child, Button will take the priority of onClick. Do the following thing
Set the property of Button to setFocusable(false);It will enable the OnClick on ListView.
For Click on Button - use onTouch instead of onClick. Which will allow you to click on button as well
try to add
android:descendantFocusability="blocksDescendants"
in the ListView tag where you define it in xml.
I have a ListView containing a checkbox, an imageview, two textviews and a button. The problem is after adding the checkbox and the button the onitemclick event of the ListView is not responding. Will anybody suggest a work around for the problem?
You can set both android:focusable and android:focusableInTouchMode attributes of checkbox to false and onItemClick of the list will be called. But you'll have to call CheckBox#toggle() yourself in onItemClick.
Add an onlick listner to the view. or the checkbox and handle it manually.
When you use checkbox in your listview then it consumes your click action and your check action will be performed.
You can put click listener over textview, imageview or button. you also need to handle checkbox.
In my main activity I have a button which I make clickable or non clickable according to a given state. However I discover that the onClickListener automatically makes it clickable again! So how to disable a button?
If you want to make your view non-clickable:
view.setClickable(false);
If you want to disable your view:
view.setEnabled(false);
Restore clickable after setting listener, for instance:
boolean isClickable = mView.isClickable();
mView.setOnClickListener(this);
mView.setClickable(isClickable);