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 onactivityresulton 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
uriusingdata.getdata(), remember received request code. make sure result codeactivity.result_ok. - feed
uri, request code (which contains item id)loaderor similar retrieve image. - store resulting image somewhere accessible
myviewholderitem id. example, can createmapinside store loaded images. - find position item id in adapter , call
notifyitemchangedon adapter position received. can call eithernotifyitemchanged(int position)full rebind, ornotifyitemchanged(int position, object payload)payloadbitmap.
Comments
Post a Comment