Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android: how to disable all clicks on a view

Tags:

android

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.

like image 628
Engin Yapici Avatar asked Feb 23 '23 15:02

Engin Yapici


1 Answers

I had a similar problem.

setEnabled(false) 

..did the job for me.

like image 141
Declan McKenna Avatar answered Mar 02 '23 20:03

Declan McKenna