LeTadas
LeTadas

Reputation: 3556

ImageView creation on photo upload

im creating an app where you can upload a photo from gallery to imageView. and i want that app to upload every new photo on new imageView. For example i picked an image from gallery press button "ok" and that photo should be uploaded on new imageView underneath existing one not in the same ImageView as it does now. Can anyone give me example how to do that or some tutorials?

Upvotes: 1

Views: 50

Answers (2)

Gilad Haimov
Gilad Haimov

Reputation: 5857

What you want is a ListView populated by images. This will also give you the ability to scroll through the loaded images.

In layout file:

<ListView
       android:id="@+id/imageList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ListView>

In the loading Activity:

 imageList = (ListView)findViewById(R.id.imageList);

 imageList.setAdapter(new MyImageAdapter());


And the adapter:

class MyImageAdapter extends BaseAdapter {

        ArrayList<Bitmap> bitmaps;

        @Override
        public int getCount() {
            return bitmaps.length;
        }

        @Override
        public Object getItem(int position) {
            return bitmaps[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup container) {
            ImageView imageView;
            if (convertView == null) { 
                imageView = new ImageView(mContext);
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); // or other..
                imageView.setLayoutParams(new GridView.LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            } else {
                imageView = (ImageView) convertView;
            }
            imageView.setImageBitmap(bitmaps[position]); // set image at appropriate position
            return imageView;
        }
    }


You'll need to pass newly loaded gallery images to the adapter's bitmaps array and do some more code tuning, but I'm sure you'll manage.

Upvotes: 2

Lectem
Lectem

Reputation: 503

You could get it working using the addview method : http://developer.android.com/reference/android/view/ViewGroup.html

Please look to this similar issue : Android - Dynamically Add Views into View

Upvotes: 0

Related Questions