views:

104

answers:

1

I am trying to make the images I have clickable so that when they are pressed it will send the user to another page or link. How do I go about this? Currently each row in the gridview has 2 buttons. How will it know which item in the gridview is clicked so that it performs a certain action, specific to the item that was clicked. Thanks for any help!

This is in my image adapter class:

// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;
    if (convertView == null) {  // if it's not recycled, initialize some attributes
        imageView = new ImageView(mContext);
        imageView.setAdjustViewBounds(true);
       // imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
        imageView.setPadding(4, 8, 4, 8);
    } else {
        imageView = (ImageView) convertView;
    }

    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

// references to our images
private Integer[] mThumbIds = {
        R.drawable.menu_about,R.drawable.menu_episodes
};

}

A: 

You may want to consider using the ImageButton class to do this for you. Its a button but instead of having a boring gray gradient you place an image there instead! Andriod ImageButton Docs From there you are free to use a click listener just like you would with a regular button.

smith324