Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to remain the selected image to the view
    primarykey
    data
    text
    <p>I have here a code for image selection, I want to select 3 or more image for my imgview but my code is showing only the image i selected and when i select another image my imgview change depending on my selection. Here's my code, i hope someone can help me. Thanks in advance.</p> <pre><code>public class BodyPartsGallery extends Activity { private Gallery gallery; private ImageView imgView; private Integer[] Imgid = { R.drawable.abdomen, R.drawable.bladder, R.drawable.kidney, R.drawable.liver, R.drawable.lungs, R.drawable.stomach, }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); if(Imgid[0] == (Imgid[0])){ imgView = (ImageView)findViewById(R.id.ImageView01); imgView.setImageResource(Imgid[0]); } else imgView = (ImageView)findViewById(R.id.ImageView02); imgView.setImageResource(Imgid[0]); gallery = (Gallery) findViewById(R.id.examplegallery); gallery.setAdapter(new AddImgAdp(this)); gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { imgView.setImageResource(Imgid[position]); } }); } public class AddImgAdp extends BaseAdapter { int GalItemBg; private Context cont; public AddImgAdp(Context c) { cont = c; TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme); GalItemBg = typArray.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0); typArray.recycle(); } public int getCount() { return Imgid.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 imgView = new ImageView(cont); imgView.setImageResource(Imgid[position]); imgView.setLayoutParams(new Gallery.LayoutParams(80, 70)); imgView.setScaleType(ImageView.ScaleType.FIT_XY); imgView.setBackgroundResource(GalItemBg); return imgView; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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