android - using a button in recycler view to open up maps -


i trying set intents button appears on card in recycler view, error startactivity(intent) part saying "cannot resolve method 'startactivity(android.content.intent)'" new , not sure going wrong code works in other parts of app.

here adapter showing code:

public class eventcalenderadapter extends recyclerview.adapter<eventcalenderadapter.viewholder> {   string[] title; string[] time_start; string[] time_finish; string[] date; string[] description; string[] loc_lat; string[] loc_long;  static class viewholder extends recyclerview.viewholder {     cardview cardview;     textview titleview;     textview auxview1;     textview auxview2;     textview auxview3;     button time_date;     button location;      public viewholder(cardview card) {         super(card);         cardview = card;         titleview = (textview) card.findviewbyid(r.id.text1);         auxview1 = (textview) card.findviewbyid(r.id.text2);         auxview2 = (textview) card.findviewbyid(r.id.text3);         auxview3 = (textview) card.findviewbyid(r.id.text4);         time_date = (button) card.findviewbyid(r.id.time_date);         location = (button) card.findviewbyid(r.id.location);     } }  public eventcalenderadapter (context context) {      title = context.getresources().getstringarray(r.array.title);     time_start = context.getresources().getstringarray(r.array.time_start);     time_finish = context.getresources().getstringarray(r.array.time_finish);     date = context.getresources().getstringarray(r.array.date);     description = context.getresources().getstringarray(r.array.description);     loc_lat = context.getresources().getstringarray(r.array.loc_lat);     loc_long = context.getresources().getstringarray(r.array.loc_long);  }  @override public viewholder oncreateviewholder(viewgroup parent, int i) {     cardview v = (cardview) layoutinflater.from(parent.getcontext()).inflate(r.layout.event_task, parent, false);     return new viewholder(v); }  @override public void onbindviewholder(viewholder viewholder, final int i) {     viewholder.titleview.settext(title[i]);     viewholder.auxview1.settext("date: "+ date[i]);     viewholder.auxview2.settext("time: " + time_start[i] + " - " + time_finish[i]);     viewholder.auxview3.settext("details: " + description[i]);      viewholder.time_date.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {          }     });      viewholder.location.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             string uri = string.format(locale.english, "geo:%f,%f", loc_lat[i], loc_long[i]);             intent intent = new intent(intent.action_view, uri.parse(uri));             startactivity(intent);         }     });  } @override public int getitemcount() {     return title.length; }   } 

you have use context call startactivity()

viewholder vh=new viewholder(card,mainactivity.this);//use 

here viewholder class

static class viewholder extends recyclerview.viewholder {     cardview cardview;     textview titleview;     textview auxview1;     textview auxview2;     textview auxview3;     button time_date;     button location;     context context;      public viewholder(cardview card,context context) {         super(card);         cardview = card;         titleview = (textview) card.findviewbyid(r.id.text1);         auxview1 = (textview) card.findviewbyid(r.id.text2);         auxview2 = (textview) card.findviewbyid(r.id.text3);         auxview3 = (textview) card.findviewbyid(r.id.text4);         time_date = (button) card.findviewbyid(r.id.time_date);         location = (button) card.findviewbyid(r.id.location);         this.context=context;     } }  public eventcalenderadapter (context context) {      title = context.getresources().getstringarray(r.array.title);     time_start = context.getresources().getstringarray(r.array.time_start);     time_finish = context.getresources().getstringarray(r.array.time_finish);     date = context.getresources().getstringarray(r.array.date);     description = context.getresources().getstringarray(r.array.description);     loc_lat = context.getresources().getstringarray(r.array.loc_lat);     loc_long = context.getresources().getstringarray(r.array.loc_long);  }  @override public viewholder oncreateviewholder(viewgroup parent, int i) {     cardview v = (cardview) layoutinflater.from(parent.getcontext()).inflate(r.layout.event_task, parent, false);     return new viewholder(v); }  @override public void onbindviewholder(viewholder viewholder, final int i) {     viewholder.titleview.settext(title[i]);     viewholder.auxview1.settext("date: "+ date[i]);     viewholder.auxview2.settext("time: " + time_start[i] + " - " + time_finish[i]);     viewholder.auxview3.settext("details: " + description[i]);      viewholder.time_date.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {          }     });      viewholder.location.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             string uri = string.format(locale.english, "geo:%f,%f", loc_lat[i], loc_long[i]);             intent intent = new intent(intent.action_view, uri.parse(uri));             context.startactivity(intent);         }     });  } @override public int getitemcount() {     return title.length; }   } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -