0

我在这里有一个图像选择代码,我想为我的 imgview 选择 3 个或更多图像,但我的代码只显示我选择的图像,当我选择另一个图像时,我的 imgview 会根据我的选择而改变。这是我的代码,我希望有人可以帮助我。提前致谢。

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;
        }
    }

}
4

1 回答 1

0

根据从先前活动中选择的 Gridview 显示图像

看看这篇文章,不完全是你在看的东西,而是类似的东西。

于 2012-07-26T05:50:10.357 回答