GridView clickable image to appear larger below

Viewed 16

I am trying to make a gridview where you can click on an image and it will appear below the gridview as a larger image. I already have the gridview setup, but I am struggling with how to create where once you click on the image, it will appear below the gridview as a larger image.

What I have so far:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    GridView gridView = (GridView) findViewById(R.id.gridview);
    gridView.setAdapter(new ImageAdapter(this));
}

}

public class ImageAdapter extends BaseAdapter { private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
}

public int getCount() {
    return mThumbIds.length;
}

public Object getItem(int position) {
    return null;
}

public long getItemId(int position) {
    return 0;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ImageView imageView;

    if (convertView == null) {
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(350,350));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(100,30,100,30);
    }
    else {
        imageView = (ImageView) convertView;
    }
    imageView.setImageResource(mThumbIds[position]);
    return imageView;
}

public Integer[] mThumbIds = {
        R.drawable.ashe, R.drawable.garen,
        R.drawable.miss_fortune, R.drawable.udyr,
        R.drawable.quinn, R.drawable.twisted_fate
};

}

0 Answers
Related