Question

i have implemented galleryview in one screen named display_image.xml in which i have shown various images available on sdcard now when user selects picture and presses save image button on same screen display_image.xml then selected image should be changed in his/her profile picture in another screen.

My question is that how would i be able to get that image from one screen to change picture of user in another screen and that selected image should also inserted in database for later retrival when user logs in later. Let me tell you that my image dont come from any webservice.

Please help me out......... Thanking You.........

Was it helpful?

Solution 3

First thing you need to do is declare an Intent

Intent i_cp = new Intent(this,ImagePicker.class);

and use startActivityForResult(i_cp, 111); which will be looking for some result. in our case for position of image; an integer value.

by specifying request_code (111) that will be used to identify result when returned by started intent. Here we wont use setAction(i_cp.ACTION_PICK); and setType("image/*"); because we are not going to return image we will just return the position of image. Our use of Intent will be limited to just passing and retrieving the integer value(position of value).

Now how about to get that position of image that user has selected. position is got in onItemClick method of GalleryView by one of the parameters

public void onItemClick(AdapterView parent, View v, int position,long rid)

now declare one variable such as int pos; and assign -1 to identify whether the image is selected or not and if the image is selected then in onclick event of button saveimage pass value position as

retIntent.putExtra("SelectedImage", pos);

and in onActivityForResult identify intent by passed requestcode and extract that position as

int pos = data.getExtras().getInt("SelectedImage");

and set it as

usr_im.setImageResource(ImagePicker.pics[pos]);

and this array of pics[] which holds all ids of images stored in one of the res/drawable folder of your application, declare it as

public static Integer[] pics={values};

Otherwise you wont able to set the image.

OTHER TIPS

You can do this by two ways : 1) Pass the path of SD card of selected image and directly load that image from path in imageview. 2) you can convert image to byes[] and passing bytes[] and get back the image.

Hope u get me. Best of Luck

Use "activityForResult".
Concept is start your image choosing activity by calling

startActivityForResult(INTENT_OF_YOUR_IMAGECHOOSING_ACTIVITY);

Now in this activity, when user clicks on any of the image handle that event as follows:
some OnClick(){<br>Intent resultIntent = new Intent(); in this intent set byte array of your image in extras OR the sd card path of your image

then call setResult(RESULT_OK, resultIntent);


This is gonna return the call to the previous activity in the method onActivityResult(int resultCode, ..., Intent data) HERE use the data as the intent to fetch the info you require

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top