2017-04-07 17 views
1

私はCalendarViewでカレンダーを表示できますが、その中にイベントを追加しようとしています。カレンダーの日付にイベントを追加することはできますか?はい、どうすれば実現できますか?ない場合は、次に何が代替解決策になるのでしょうか?私は、2つ以上のday.pleaseヘルプJSONデータ(イベント)をカレンダー内に読み込むことはできますか?

カレンダー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); 
     } 
    } 

} 
のためにそれに捕まってしまいました

JSONデータからカレンダー内でイベントを追加するにはどうすればよいですか?

答えて

0

あなたの質問を理解してください、あなたはイベントのフォームjsonデータを追加しますか?はい、あなたの

  1. を行う必要

    解析JSONデータ

  2. は(コンテンツプロバイダを使用して、カレンダーにイベントを追加した場合 は、ここでいくつかのリンクを助けることができるかは、Google カレンダーコンテンツプロバイダに検索することができますです

https://developer.android.com/guide/topics/providers/calendar-provider.html

あなたはについての知識を持っていない場合 アンドロイドコンテンツプロバイダに関する最初の研究を示唆

How to read and edit Android calendar events using the new Android 4.0 Ice Cream Sandwich API?

https://developer.android.com/guide/topics/providers/content-providers.html

データのソート:

  1. 複雑なデータは、あなたがデータを格納するためのモデルクラスを必要な場合にのみ、単一の値のデータは、非常に単純な方法 http://beginnersbook.com/2013/12/how-to-sort-arraylist-in-java/

  2. が並べ替えないことができている場合と、並べ替えのための任意のオブジェクトを使用してください(私はあなたがGoogleで検索することができます休憩を掲示します)Sort ArrayList<class> in Java

+0

私はほぼすべての仕事をしています。私はcalendarViewの下にlistViewを作成し、events.Butを表示することができました。私はmonth.Canによって特定のイベントを表示したいです。チェック。私は今これを取得しています – Ghimire

+0

あなたがカレンダーにあなたのデータを入れたら、簡単にイベントの月を見せてください。しかし、私はあなたがリストに直接データを表示しているのを見ることができます。したがって、データ構造とソートを使用する必要があります。同じコンセプトのアプリが1つありますが、私はcalendar api(https://play.google.com/store/apps/details?id=oca.eyehunt.in.oca)を使用しました – rkkanojia7

+0

datastructueとソートの使い方を教えてください – Ghimire

関連する問題