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.