开发者

Disabling focus in TextView

开发者 https://www.devze.com 2023-01-09 00:05 出处:网络
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:

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 开发者_C百科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.


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消