android - Using shared element transitions from a non-activity class to an activity class -


i have non-activty class (precisely recyclerview adapter holding cardviews), trying use "authentic motion" transition cardview final activity using shared image element. implemented between 2 activity classes non-activity class activity class, unable so?

here's code (recyclerviewadapter.java):

public class rvadapter extends recyclerview.adapter {

public static class personviewholder extends recyclerview.viewholder {       cardview cv;     textview personname;     textview personage;     imageview personphoto;     textview myid;     front ft = new front();      personviewholder(view itemview) {         super(itemview);         personname = (textview)itemview.findviewbyid(r.id.person_name);         personage = (textview)itemview.findviewbyid(r.id.person_age);         personphoto = (imageview)itemview.findviewbyid(r.id.person_photo);         myid = (textview)itemview.findviewbyid(r.id.idtag);         cv = (cardview)itemview.findviewbyid(r.id.cv);         cv.setusecompatpadding(true);         cv.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                   final string cardid = myid.gettext().tostring().trim();                 intent callintent = new intent("io.brushed.databasecardview.viewdatainside");                 callintent.setflags(intent.flag_activity_new_task);                 callintent.putextra("theid",cardid);                 string transitionname = "oktrans";                 activityoptionscompat options = activityoptionscompat.makescenetransitionanimation(this,                         personphoto,   // view starts transition                         transitionname    // transitionname of view we’re transitioning                 );                 activitycompat.startactivity(this, callintent, options.tobundle());              }         });        } }  list<person> persons;  rvadapter(list<person> persons){     this.persons = persons; }  @override public void onattachedtorecyclerview(recyclerview recyclerview) {     super.onattachedtorecyclerview(recyclerview); }  @override public personviewholder oncreateviewholder(viewgroup viewgroup, int i) {     view v = layoutinflater.from(viewgroup.getcontext()).inflate(r.layout.item, viewgroup, false);     personviewholder pvh = new personviewholder(v);     return pvh; }  @override public void onbindviewholder(personviewholder personviewholder, int i) {     personviewholder.myid.settext(persons.get(i).id);     personviewholder.personname.settext(persons.get(i).name);     personviewholder.personage.settext(persons.get(i).age);     personviewholder.personphoto.setimageresource(persons.get(i).photoid); } @override public int getitemcount() {     return persons.size(); }  } 

its not able resolve "this" keyword, supposed replace recyclerview adapter non-activity class?

you can pass context of activity class non-activty class (precisely recyclerview adapter holding cardviews)

e.g.

recyclerviewadapter1(context context...) 

then use context purpose:

string transitionname = "oktrans"; activityoptionscompat options = activityoptionscompat.makescenetransitionanimation(this, personphoto,transitionname); activitycompat.startactivity(context, callintent, options.tobundle());   

edit:

based on new edit.

pass activity argument.

personalviewholder(view view, activity activity) { ... activitycompat.startactivity(activity, ...); }  public static class personviewholder extends recyclerview.viewholder {   cardview cv; textview personname; textview personage; imageview personphoto; textview myid; front ft = new front();  personviewholder(view itemview, final context context) {     super(itemview);     personname = (textview)itemview.findviewbyid(r.id.person_name);     personage = (textview)itemview.findviewbyid(r.id.person_age);     personphoto = (imageview)itemview.findviewbyid(r.id.person_photo);     myid = (textview)itemview.findviewbyid(r.id.idtag);     cv = (cardview)itemview.findviewbyid(r.id.cv);     cv.setusecompatpadding(true);     cv.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {               final string cardid = myid.gettext().tostring().trim();             intent callintent = new intent("io.brushed.databasecardview.viewdatainside");             callintent.setflags(intent.flag_activity_new_task);             callintent.putextra("theid",cardid);             string transitionname = "oktrans";             activityoptionscompat options = activityoptionscompat.makescenetransitionanimation(context,                     personphoto,   // view starts transition                     transitionname    // transitionname of view we’re transitioning             );             activitycompat.startactivity(context, callintent, options.tobundle());          }     });    } 

}

list<person> persons;  rvadapter(list<person> persons){ this.persons = persons; }  @override  public void onattachedtorecyclerview(recyclerview recyclerview) { super.onattachedtorecyclerview(recyclerview);  }   @override  public personviewholder oncreateviewholder(viewgroup viewgroup, int i)   {    view v =    layoutinflater.from(viewgroup.getcontext()).inflate(r.layout.item,   viewgroup, false);    personviewholder pvh = new personviewholder(v, viewgroup.getcontext());   return pvh;  }  @override public void onbindviewholder(personviewholder personviewholder, int i)    { personviewholder.myid.settext(persons.get(i).id); personviewholder.personname.settext(persons.get(i).name); personviewholder.personage.settext(persons.get(i).age); personviewholder.personphoto.setimageresource(persons.get(i).photoid); } @override public int getitemcount() { return persons.size(); }  } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -