-4

I need to implement a UI which displays many images(more than 1000). The layout of the images like this:

(image1)  (image2)  (image3)
  ( image4 )    ( image5 )
  ( image6 )    ( image7 )
     ...
  ( imageN )    ( imageN+1)

I want to show these images in a ListView and I know how to do that. But, I don't know how to identify which image is clicked after showing them. I need to display a big image after clicking the little image in the ListView. Any answer will be appreciated.

Edit 1: if it is hard for a ListView to do this, is it possible to use a GridView to implement this kind of layout?

Lei Guo
  • 2,550
  • 1
  • 17
  • 22
  • you should have an id for the clicked list item, use that to determine what image it is. – zapl Apr 19 '12 at 13:43
  • But the id can be used to identify different rows only, still can't know which image is clicke since there are 2 or 3 image in a row. – Lei Guo Apr 19 '12 at 14:32
  • http://stackoverflow.com/questions/1709166/android-listview-elements-with-multiple-clickable-buttons - you need to set onclick listeners to each image then. – zapl Apr 19 '12 at 14:54

1 Answers1

1

You can create an ArrayList of ImageView, and add all imageView objects in it. Then just call setOnTouchListener to all elements of the arraylist using loop. In the OnTouch(View v, MotioNEvent event) method, the View v is your imageView.

for example:

for(int i=0;i<imageArray.size();i++){
    imageArray.get(i).setOnTouchListener(new OnTouchListener(){
        protected boolean onTouch(View v, MotionEvent event){
            //v is your image on which the touch event happened.
        }
    });
}
0xC0DED00D
  • 19,522
  • 20
  • 117
  • 184
  • All the imageViews are managed by the ListAdapter, so I add an OnClickeListener for each imageViews in the function getView(...) of the ListAdapter. But when I click the image nothing happens. Seems the image didn't know it is clicked, what's the problem? – Lei Guo Apr 19 '12 at 14:51
  • This is not a problem, the imageViews can know it is clicked after setting the OnClickListener. – Lei Guo Apr 19 '12 at 15:58
  • No problem. By the way you can always accept the answer if it worked, so that other readers facing similar problems get to know which solution works best. – 0xC0DED00D Apr 23 '12 at 13:54