I have a horizontalscrollview inside which i have a bunch of images. Now i need to detect the click event in case any of the image is clicked within it. In short, i need the index of the image placed inside the horizontalscrollview, which was clicked.
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bgcolor" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageview1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:src="@drawable/image1" />
<ImageView
android:id="@+id/imageview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingRight="20dp"
android:src="@drawable/image2" />
I tried playing around OnTouchListener event, but that was getting triggered even while scrolling. And the OnClickListener was not even getting triggered no matter wherever you click.
horizontalScrollView1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("Testing scrollview");
}
});
Is there a workaround to get the index of the clicked image present inside the horizontalscrollview? I guess it can be achieved via "Gallery" widget but that is deprecated in API16. Can anyone share an approach to accomplish this via HorizontalScrollView?