问题
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