I am able to show the Calendar with CalendarView but got stuck to add events within it.Can we add events to the date in the calendar through the JSON Data.If yes how can this be achieved? if not then what would be the alternative solution?I got stuck in it for more than 2 day.please help
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);
for (int i = 0; i < 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:
// do s.th.
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
How can events be added within calendar through JSON Data?