Showing Selected Grid Image in New Activity (Full Screen)
Selasa, 08 Januari 2013
0
komentar
create a new java file with an image view:
gridView = (GridView) findViewById(R.id.gridView1);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView parent,View v,int position,long id)
{
System.out.println("====>>"+position);
Intent i = new Intent(getApplicationContext(),GidImage.class);
// passing array index
i.putExtra("id", position);
startActivity(i);
}
});
in custom Adapter class:
Intent i = getIntent();
// Selected image id
int position = i.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
ImageView imageView =(ImageView)
findViewById(R.id.full_image_view);
imageView.setImageResource(imageAdapter.mThumbIds[position]);
public class ImageAdapter extends BaseAdapter {
private Context context;
public Integer[] mThumbIds = {
R.drawable.card0, R.drawable.card1,
R.drawable.card2, R.drawable.card3,
R.drawable.card0, R.drawable.card1,
R.drawable.card2, R.drawable.card3,
R.drawable.card0, R.drawable.card1,
R.drawable.card2, R.drawable.card3
};
public ImageAdapter(Context context) {
this.context = context;
}
@Override
public int getCount() {
return mThumbIds.length;
}
@Override
public Object getItem(int position) {
return mThumbIds[position];
}
@Override
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(mThumbIds[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(130, 100));
imageView.setPadding(8, 8, 8, 8);
return imageView;
}
}
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Showing Selected Grid Image in New Activity (Full Screen)
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://androidpopuler.blogspot.com/2013/01/showing-selected-grid-image-in-new.html. Terima kasih sudah singgah membaca artikel ini.Ditulis oleh Unknown
Rating Blog 5 dari 5
0 komentar:
Posting Komentar