It’s easy to disable a button when I use listeners like this:
button.setOnClickListener(btnSub);
button.setEnabled(false);
But when I use the onClick for the button in the XML file and just call a method in the main file, is it possible to reach that button an disable it?
If you are using the xml layout to set the on-click function of your button, then you use something like this, right?:
If you take a look at the documentation, it says, that you need to supply a function for this, what takes a
Viewparameter.So you need to implement
yourFunctionthis way:The
View, what you get in that function, is theButton(or any otherView) what you clicked.So you just need to implement that function like this:
EDIT
If you give that
Buttonan id with the following xml attribute:Then you can access that
View(Button) from yourActivity(orDialog):and enable it: