horizontalscrollview onclicklistener doesn't get called

雨燕双飞 提交于 2019-12-13 05:16:13

问题


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


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/19395830/horizontalscrollview-onclicklistener-doesnt-get-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!