开发者

Selector for listview row child view

开发者 https://www.devze.com 2023-01-29 04:55 出处:网络
I have a list view, and the row view has 2 child views: an image view and a text view. The image view is actionable. Both of the child views have a selector. My problem is that when I press the text v

I have a list view, and the row view has 2 child views: an image view and a text view. The image view is actionable. Both of the child views have a selector. My problem is that when I press the text view the image view gets selected t开发者_如何学运维oo. Is like the row view transmits the selected state to it's children. How can I remove that so each child view gets selected independently?

Best regards, Gratzi


in the xml for listview use android:listSelector="@null". If this does not work out then in the adapter you can override 2 methods to achieve this,

        @Override
        public boolean isEnabled(int position)
        {
            return false;
        }

        @Override
        public boolean areAllItemsEnabled()
        {
            return false;
        }

This will remove the selection that happens for the row. But for the highlight to happen separately you will have to write a statelist or manage it manually.


I did it by creating a listener for the text view, and moving the code from the list view listener in the text view listener. In this way the pressed event won't get to the row view and the row wont delegate it to the image view. I'm not fully satisfied with this solution because I have to create a listener for the text view every time a list row is created (every time the bindView method is called), but this is the best solution I could find.

0

精彩评论

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