android - onActivityResult in RecyclerView.Adapter<MyAdapter.MyViewHolder> -
i tried open gallery adapter.
emp_photo_edit.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = new intent(intent.action_pick,android.provider.mediastore.images.media.external_content_uri); ((employeeactivity)context).startactivityforresult(i, 2017); } });
then want show choosen image imageview
in recycycleview
, how that? because cant add onactivityresult
on adapter
. in advance
edit
my full code
public static class myviewholder extends recyclerview.viewholder { .... public myviewholder(view v) { super(v); .... } public void bind(final employee item, final onitemclicklistener listener, final context context) { .... generatedialog(item,dialog_employee); .... } ... ... void generatedialog(employee item, view v){ //dialog child //photo emp_photo_edit.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent = new intent(intent.action_pick,android.provider.mediastore.images.media.external_content_uri); ((employeeactivity)context).startactivityforresult(i, 2017); } }); .... } }
your result arrive in employeeactivity
in onactivityresult
. since picking image, result uri
have retrieve first, bind appropriate item. suggest following sequence of actions:
- create new request code stores item position , identifies request. if there no other requests, can make row id request code.
- get
uri
usingdata.getdata()
, remember received request code. make sure result codeactivity.result_ok
. - feed
uri
, request code (which contains item id)loader
or similar retrieve image. - store resulting image somewhere accessible
myviewholder
item id. example, can createmap
inside store loaded images. - find position item id in adapter , call
notifyitemchanged
on adapter position received. can call eithernotifyitemchanged(int position)
full rebind, ornotifyitemchanged(int position, object payload)
payload
bitmap.
Comments
Post a Comment