I have set mButton.setClickable(false);
in my code but still this button is invoked by global button.setOnClickListener
of my code.
EDIT: sorry for the delayed update. Below is the details view where I face the issue.
inside my listview customAdapter class getView method
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
YourWrapper wrapper = null;
HashMap<String, Object> cTa= new HashMap<String, Object>();
cTa= d.getPosition(position)
Button mButton = (Button)convertView.findViewById(R.id.mBtn);
if (row == null)
{
row = inflater.inflate(R.layout.layout, parent, false);
wrapper = new YourWrapper (row);
row.setTag(wrapper);
}
else
wrapper = (YourWrapper) row.getTag();
if(success)
{
// section-1
mButton.setClickable(true);
}
else{
// section-2
mButton.setClickable(false);
mButton.setFocusable(false);
}
wrapper.getButton().setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//operation
}
});
return row;
}
Above is the current code which working,and on section-2 it makes the mButton clickable- false, and focusable - false but still it's listen the below wrapper.getButton().setOnClickListener() and perform the operation. Please suggest me. Sorry for delayed update. Thanks!
UPDATE: I have made below hot-fixes that solve the problem for now.
// section-2
mButton.setVisibility(View.GONE);
mButton.setClickable(false);
mButton.setFocusable(false);
3 Answers. Show activity on this post. setClickable(false) on LinearLayout without child view not working. onClickListener always fire when clicked.
I tried with button. setclickable(false) and button. setEnabled(false) both dint worked for me.
You need to put the setOnClickListener in one of the activity callbacks. In your onCreate() method, move the button there and then setOnClickListener() . Show activity on this post.
That seems to be by design. This is from the documentation of the View.setOnClickListener method:
Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.
Instead of using setClickable(false)
use setEnabled(false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With