Engin Yapici
Engin Yapici

Reputation: 6174

android: how to disable all clicks on a view

I am trying to set all the properties of a view in a listview row that will react to clicks (it can be a simple press, a long click or anything else). I tried to set both parent and child views' .setFocusable, .setFocusableInTouchMode, .setLongClickable, .setClickable, .setPressed, .setSelected, .setHapticFeedbackEnabled attributes to false but it did not help.

I am switching between two states of a listview with a button click. When I switch to second state I would like to disable all the clicks on the rows. I am populating the each state of listview with different custom cursoradapters. The following code snippet is from my second cursoradapter for second state:

@Override
public void bindView(View view, Context context, Cursor cursor) {
    RelativeLayout parent = (RelativeLayout) view.findViewById(R.id.title_rows_relativelayout);
    TextView lists_text = (TextView) view.findViewById(R.id.list_title_text);
    lists_text.setText(cursor.getString(cursor.getColumnIndex(ListsDbAdapter.TITLE)));
    lists_text.setBackgroundResource(R.drawable.background_for_rows);
    parent.setBackgroundResource(R.drawable.background_for_rows);

    view.setFocusable(false);
    view.setFocusableInTouchMode(false);
    view.setHapticFeedbackEnabled(false);
    view.setLongClickable(false);
    view.setClickable(false);
    view.setPressed(false);
    view.setSelected(false);

    parent.setFocusable(false);
    parent.setFocusableInTouchMode(false);
    parent.setHapticFeedbackEnabled(false);
    parent.setLongClickable(false);
    parent.setClickable(false);
    parent.setPressed(false);
    parent.setSelected(false);

    lists_text.setFocusable(false);
    lists_text.setFocusableInTouchMode(false);
    lists_text.setHapticFeedbackEnabled(false);
    lists_text.setLongClickable(false);
    lists_text.setClickable(false);
    lists_text.setPressed(false);
    lists_text.setSelected(false);
}

Thank you in advance.

Upvotes: 4

Views: 11213

Answers (2)

Declan McKenna
Declan McKenna

Reputation: 4930

I had a similar problem.

setEnabled(false) 

..did the job for me.

Upvotes: 9

Kurtis Nusbaum
Kurtis Nusbaum

Reputation: 30845

If I'm understanding you correctly, you shouldn't need two adapters. You can just use one and add and onClickListener to the view that disables everything like so:

view.setOnClickListener(new View.onClickListener(){
  public void onClick(View view){
    //do all your code for disabling stuff in here
  }
});

Perhaps doing this and not having to switch between adapters will help you.

Upvotes: 1

Related Questions