Any listener is possible if the condition

I am doing this for the code, but not supported for this problem, and what am I doing to solve it, as if encoding is inside any listener.

if (btn.isEnabled()) { btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub } }); } 
+6
source share
2 answers

But why???

any onClickListener button will be called only if it is enabled. You do not need to worry about onClickListeners that are assigned to disabledButtons.

Suppose your button is disabled at startup, then this listener will not be applied to your button. Now after a while, if you turn on this button (maybe after some event, etc.), "THEN ALSO LISTEN TO THIS WORK", since you did not put the listener in the first place ...

therefore IMO does not insert this if ...

0
source

this code is successful.

 if (button.isEnabled()) { button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Toast.makeText(getApplicationContext(), "Test", 10).show(); } }); } 
0
source

All Articles