android - Can we Load JSON Data(Events) within Calendar? -
i able show calendar calendarview got stuck add events within it.can add events date in calendar through json data.if yes how can achieved? if not alternative solution?i got stuck in more 2 day.please
calendar xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#2e353d" android:orientation="vertical"> <linearlayout android:layout_width="wrap_content" android:layout_height="40dp" android:layout_gravity="center_horizontal" android:orientation="horizontal"> <imageview android:layout_width="30dp" android:layout_height="match_parent" android:padding="3dp" android:src="@mipmap/calander" /> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginleft="8dp" android:text="calendar" android:textcolor="#fff" android:textsize="17dp" android:textstyle="bold" /> </linearlayout> </linearlayout> <calendarview android:id="@+id/calendar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerinparent="true" /> <listview android:id="@+id/calenderlist" android:layout_width="match_parent" android:layout_height="wrap_content" /> </linearlayout>
calenderfragment
public class calenderfragment extends fragment { calendarview calendar; string navigation_url = "http://192.168.100.5:84/api/academics/getevents"; string access_token; listview listview; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.calender, container, false); getactivity().settitle(""); sethasoptionsmenu(true); calendar = (calendarview) view.findviewbyid(r.id.calendar); calendar.setondatechangelistener(new calendarview.ondatechangelistener() { @override public void onselecteddaychange(calendarview view, int year, int month, int dayofmonth) { toast.maketext(getcontext(), dayofmonth + "/" + month + "/" + year, toast.length_long).show(); } }); listview = (listview) view.findviewbyid(r.id.calenderlist); sessionmanagement session = new sessionmanagement(getcontext()); session.checklogin(); access_token = session.getaccessttoken(); makejsonobjectrequest(); return view; } private void makejsonobjectrequest() { requestqueue requestqueue = volley.newrequestqueue(getcontext()); string url = navigation_url; stringrequest stringrequest = new stringrequest(request.method.get, url, new response.listener<string>() { @override public void onresponse(string response) { try { arraylist<calenderpojostudent> student_list_calender = new arraylist<>(); jsonarray jarray = new jsonarray(response); (int = 0; < jarray.length(); i++) { jsonobject jsonobject = jarray.getjsonobject(i); string startat = jsonobject.getstring("startat").substring(6, 10); string title = jsonobject.getstring("title"); student_list_calender.add(new calenderpojostudent(startat, title)); } calenderadapter calenderadapter = new calenderadapter(getactivity(), student_list_calender); listview.setadapter(calenderadapter); } catch (jsonexception e) { toast.maketext(getcontext(), "fetch failed!", toast.length_short).show(); e.printstacktrace(); } } }, new response.errorlistener() { @override public void onerrorresponse(volleyerror error) { toast.maketext(getcontext(), error.tostring(), toast.length_long).show(); } }) { @override public map<string, string> getheaders() throws authfailureerror { map<string, string> headers = new hashmap<string, string>(); headers.put("authorization", "bearer " + access_token); headers.put("content-type", "application/x-www-form-urlencoded"); return headers; } /* @override protected map<string, string> getparams() throws com.android.volley.authfailureerror { map<string, string> map = new hashmap<string, string>(); map.put("id", master_id); map.put("accessid", accessid); map.put("currentuser", master_id); return map; } */ }; requestqueue.add(stringrequest); } @override public void oncreateoptionsmenu(menu menu, menuinflater inflater) { // todo auto-generated method stub super.oncreateoptionsmenu(menu, inflater); inflater.inflate(r.menu.dashboard, menu); } @override public boolean onoptionsitemselected(menuitem item) { // handle item selection switch (item.getitemid()) { case r.id.action_settings: // s.th. return true; default: return super.onoptionsitemselected(item); } } }
how can events added within calendar through json data?
let me understand question , want add event form json data? if yes need do
parse json data
add event in calendar using content provider (here links can or can search in google calendar content provider)
https://developer.android.com/guide/topics/providers/calendar-provider.html
how read , edit android calendar events using new android 4.0 ice cream sandwich api?
suggesting first study android content provider if don't have knowledge about. https://developer.android.com/guide/topics/providers/content-providers.html
sorting of data :
if there single value data can sorting simple way http://beginnersbook.com/2013/12/how-to-sort-arraylist-in-java/
if complex data needed model class store data , use object sorting (one example posting rest can search in google) sort arraylist<class> in java
Comments
Post a Comment