views:

51

answers:

1

Hello,

In an Android application I have a ListActivity. After creating it I have a broadcast receiver which has to disable some items in the list. So I have a pice of code ike this one:

View child = getListView().getChildAt(i);
child.setEnabled(false);

It works in the way it changes the color of the disabled views to gray. But I need to avoid this items can be clicked. So I've tried to call

child.setFocusable(false);

or

child.setClickable(false);

but in both cases onListItemClick is called after pressing on a disabled option.

How can I avoid that onListItemClick method is called when these textviews are clicked?

Thanks.

+1  A: 

Disabling the views does nothing with regard to the onListItemClick event.

The child must be disabled by the Adapter you are using to populate the list.

See http://developer.android.com/reference/android/widget/ListAdapter.html#isEnabled(int)

This method needs to be overriden to return false for each item you do not want to be clickable. You should also add a method to your adapter like setEnabled(int position, boolean enabled)

CodeFusionMobile