onItemClick on GalleryView
I am displaying multiple images using the Gallery class
I am using the following code to
private SampleGallery mGalleryView1 = null;
mGalleryView1 = (SampleGallery) findViewById(R.id.galleryView1);
mGalleryView1.setOnItemClickListener(this);
SampleGallery class extends the Gallery
The problem I am facing is that , when I am clicking on the images,
from the following method
public void onItemClick(AdapterView<?> l, View v, int position, long i开发者_如何学编程d) {}
I am getting the position of the image as a no like "13878342720" & not any value like "0" , "1" .
Actually based on the position value , I am doing some logical calculations , so am ending getting the "ArrayIndexOutOfBoundsException" , since the position value is returning nothing.
Kindly provide your inputs , why the position is being returned so.
Seems like following line in your code is causing this
private SampleGallery mGalleryView1 = null;
this is setting your gallery to null
and thats why you getting garbage position in your onItemClick listener.
Have you tried adding some elements to it and then clicking on it?
You are declaring mGalleryView1
as SampleGallery
,but your are tycasting that as ZoomGallery
.You must declare your mGalleryView1
as you mention your galleryView1
in your layout XML.
I found out that the from the following code
public void onItemClick(AdapterView<?> l, View v, int position, long id) {}
in my case , long id is returning me the exact position when I am clicking the images on the gallery.
int localPostion = (int) id ;
Now, I can use the localPosition & use if for the logical calculations
精彩评论