Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Simply use getItemAtPosition() to get the clicked object:</p> <p>You can find some more info here: <a href="http://developer.android.com/resources/tutorials/views/hello-gallery.html" rel="nofollow">http://developer.android.com/resources/tutorials/views/hello-gallery.html</a> <br/> <b>Edited:</b> <br/><br/> Assign the URL inside getView() in your ImageAdapter: <br/></p> <pre><code>public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; private Context mContext; private Integer[] mImageIds = { R.drawable.sample_1, R.drawable.sample_2 }; private String[] mImageURLs = { "http://www.example1.com", "http://www.example2.com" }; public ImageAdapter(Context c) { mContext = c; TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGallery); mGalleryItemBackground = attr.getResourceId( R.styleable.HelloGallery_android_galleryItemBackground, 0); attr.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView = new ImageView(mContext); imageView.setImageResource(mImageIds[position]); //Add url imageView.setTag(mImageURLs[position]); imageView.setLayoutParams(new Gallery.LayoutParams(150, 100)); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setBackgroundResource(mGalleryItemBackground); return imageView; } </code></pre> <p>}</p> <p><br/> And then read that urs inside OnItemClick(): <br/></p> <pre><code>gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { String url = view.getTag().toString(); //next use this url to open in a browser } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload