horizontalscrollview onclicklistener doesn't g

2019-09-09 02:18发布

i have horizontalscrollview displaying some items. The items are added dynamically. i want to show a alert box when the horizontalscrollview is clicked. there may or may not be any items in the horizontalscrollview so i want the horizontalscrollview to take the cick. But OnClickListener dosint get called

scrolv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                slowAlert();
            }
        });

showAlert() never gets called

3条回答
你好瞎i
2楼-- · 2019-09-09 02:49

heyy just try this just put ClickListener not on scroll view but on the child of that scroll view like relative or linear layout bcoz all your item in that layout also i think its work. and if you try on screen touch then may be it difficult because all screen work in this idea so try my idea of child layout

查看更多
戒情不戒烟
3楼-- · 2019-09-09 03:01

One thing you could do is have the click listener on the view that contains the horizontal scrollsview. Along with this you could have each view in the HSV clickable aswell.

查看更多
We Are One
4楼-- · 2019-09-09 03:12

Perhaps the event is being consumed before the click is fired? try using onTouch() instead of onClick().

If the problem is that the other items are consuming the even rather than the scroll you may have to use a loop to add the listener to all the items added to the scroll.

查看更多
登录 后发表回答