DroidVasu
DroidVasu

Reputation: 27

how I upload multiple images in to different ImageView?

I need to upload 2 different image in to different image view. How can I upload?

Here is my xml sample file.

<RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

      <ImageView
        android:id="@+id/uivProfileImage"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginLeft="10dp"
        android:layout_marginStart="10dp"
        android:adjustViewBounds="true"
        android:contentDescription="@null"
        android:maxHeight="100dp"
        android:maxWidth="100dp"
        android:scaleType="fitXY" />

    <ImageView
        android:id="@+id/uivProfileCoverImage"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_toRightOf="@+id/uivProfileImage"
        android:adjustViewBounds="true"
        android:contentDescription="@null"
        android:maxHeight="100dp"
        android:scaleType="fitXY" />

</RelativeLayout>

Upvotes: 1

Views: 1639

Answers (1)

RediOne1
RediOne1

Reputation: 10719

Use request code to distinguish which ImageView was clicked, for example

Intent intent = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(intent, PICK_FIRST_IMAGE);

where PICK_FIRST_IMAGE is int value equals 100

Intent intent = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(intent, PICK_SECOND_IMAGE);

where PICK_SECOND_IMAGE is int value equals 101.

Then in onActivityResult you can do something like this:

public void onActivityResult(int requestCode, int resultCode,
            Intent data) {
            if (resultCode == Activity.RESULT_OK) {

                ...

                if(requestCode == PICK_FIRST_IMAGE)
                    firstImageView.setImageBitmap(yourSelectedImage);
                else
                    secondImageView.setImageBitmap(yourSelectedImage);
            }

Upvotes: 1

Related Questions