Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button.setClickable(false) is not working

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);
like image 352
Pradip Avatar asked Sep 16 '13 10:09

Pradip


People also ask

How do you make a clickable fake?

3 Answers. Show activity on this post. setClickable(false) on LinearLayout without child view not working. onClickListener always fire when clicked.

How do I make my switch not clickable Android?

I tried with button. setclickable(false) and button. setEnabled(false) both dint worked for me.

Why my setOnClickListener is not working?

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.


2 Answers

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.

like image 156
Jan Avatar answered Sep 21 '22 11:09

Jan


Instead of using setClickable(false) use setEnabled(false)

like image 38
joecizac Avatar answered Sep 22 '22 11:09

joecizac