android - transferring data from string arrays into another activity -
i have fragment recycler view , adaptor accesses string arrays, shown in recycler view. question how can transfer data held in these arrays new activity, when user clicks on selected item brings more information held in these arrays. not sure how can done, have tried putting values array list can't seem work, new this. thank in advance
this fragment
public class eventcalenderfragment extends fragment { recyclerview recyclerview; eventcalenderadapter adapter; public eventcalenderfragment() { // required empty public constructor } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); adapter = new eventcalenderadapter(getactivity()); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { final view v = inflater.inflate(r.layout.fragment_event_calender, container, false); recyclerview = (recyclerview) v.findviewbyid(r.id.recycler); recyclerview.setadapter(adapter); recyclerview.sethasfixedsize(true); recyclerview.setlayoutmanager(new linearlayoutmanager(getactivity())); return v; } }
this adapter
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; public viewholder(cardview card) { super(card); cardview = card; titleview = (textview) card.findviewbyid(r.id.text1); auxview1 = (textview) card.findviewbyid(r.id.text2); } } 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) { final context context = viewholder.titleview.getcontext(); viewholder.titleview.settext(title[i]); viewholder.auxview1.settext("date: "+ date[i] + " start: " + time_start[i] + " finish: " + time_finish[i]); viewholder.cardview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { ((oneventview) context).eventview(i); } }); } @override public int getitemcount() { return title.length; } }
and fragment access data
public class eventviewfragment extends fragment { public static final string default_fragment_tag = "eventviewfragment"; static final string event_id = "eventid"; view rootview; textview title; textview description; textview date_time; textview location; long eventid; public static eventviewfragment newinstance(long id) { eventviewfragment fragment = new eventviewfragment(); bundle args = new bundle(); args.putlong(eventviewactivity.view_eventid, id); fragment.setarguments(args); return fragment; } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); bundle arguments = getarguments(); if (arguments != null) { eventid = arguments.getlong(eventviewactivity.view_eventid, 0l); } if (savedinstancestate != null) { eventid = savedinstancestate.getlong(event_id); } } @override public void onsaveinstancestate(bundle outstate) { super.onsaveinstancestate(outstate); outstate.putlong(event_id, eventid); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.fragment_event_view, container, false); rootview = v.getrootview(); title = (textview) v.findviewbyid(r.id.title); description = (textview) v.findviewbyid(r.id.description); date_time = (textview) v.findviewbyid(r.id.time_date); location = (textview) v.findviewbyid(r.id.location); date_time.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { } }); location.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { } }); return v; } }
once try follows in first activity
intent i=new intent(getactivity(),nextactivity.class); i.putstringarraylistextra("title", (arraylist) arrays.aslist(title)); i.putstringarraylistextra("time_start",(arraylist)arrays.aslist(time_start)); i.putstringarraylistextra("time_finish",(arraylist)arrays.aslist(time_finish)); i.putstringarraylistextra("date",(arraylist)arrays.aslist(date)); i.putstringarraylistextra("description",(arraylist)arrays.aslist(description)); i.putstringarraylistextra("loc_lat",(arraylist)arrays.aslist(loc_lat)); i.putstringarraylistextra("loc_long",(arraylist)arrays.aslist(loc_long));
and in next activity
list<string> title1=getintent().getstringarraylistextra("title"); ........................................ ..........................................
hope helps you.
Comments
Post a Comment