当前位置: 动力学知识库 > 问答 > 编程问答 >

How do I prevent clicking elements in a ListView row when in MutliChoiceMode in Android

问题描述:

I have a Listview set up with a custom adapter. Each of the ListView's rows has a button and a seekbar that the user can interact with. I have also implemented a MultiChoiceModeListener to handle long clicking a ListView row in order to allow the user to delete multiple rows.

What I need is to prevent the user from interacting with each of the ListView's row elements (buttons, seekbars etc) when the ListView is in MultiSelect mode, by disabling them, and then to enable them once the user exits the multiselect mode.

Is there a simple way to do this? I've tried adding:

 for(int i = 0; i < adapter.getCount(); i++){

View v = promptListView.getChildAt(i);

v.setEnabled(false);

}

to the onCreateActionMode() method, but with no success, I'm still able to interact with the row elements. Any help would be greatly appreciated, thanks.

网友答案:

You can check if you want the list item elements to interact to touch inside your custom adapter, so you can either set listeners there or disable them.

网友答案:

Add the property android:descendantFocusability="blocksDescendants" to the layout root of your list row. This will prevent the children from gaining focus, and will enable the user to click on the list row or any of its child views independently. Now you can disable (gray out) and re-enable any of the child views by using setEnabled() like you do in your code. Or if you would just like to prevent the user from being able to interact with a view without graying it out, you can use setClickable() instead.

分享给朋友:
您可能感兴趣的文章:
随机阅读: