我应该在哪里放“values.put(CalendarProvider.COLOR,Event.COLOR_RED);”在这段代码中

时间:2014-12-26 12:20:22

标签: android events calendar android-calendar calendarview

我正在使用tyczj的ExtendedCalendarView作为应用程序的一部分。我从external server database检索了事件。但是,在ExtendedCalendarView文档中,他们手动添加了事件,以便颜色点可以工作。这个person能够在日期上实现颜色。我可以知道如何在代码中实现values.put(CalendarProvider.COLOR, Event.COLOR_RED);吗?

我的java代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.calendarfilter, container, false);

    listView = (ListView)rootView.findViewById(R.id.listView1);
    eventsList = new ArrayList<HashMap<String, Object>>();


    ExtendedCalendarView calendar = (ExtendedCalendarView)rootView.findViewById(R.id.calendar);
    //ContentValues values = new ContentValues();
    //values.put(CalendarProvider.COLOR, com.tyczj.extendedcalendarview.Event.COLOR_RED);
           calendar.setOnDayClickListener(new OnDayClickListener() {

            @Override
            public void onDayClicked(AdapterView<?> adapter, View view,
                    int position, long id, Day day) {
                day.getDay();
                int perfectmonth = day.getMonth()+1;
                perfectdate = day.getYear() + "-" + perfectmonth + "-" + day.getDay();
                Toast.makeText(getActivity(), ""+ perfectdate , Toast.LENGTH_SHORT).show();

                eventsList.clear();

                 accessWebService();
            }
            });

           Bundle extras = getActivity().getIntent().getExtras();
           value = extras.getString("ad");




    return rootView;
}




// Async Task to access the web
private class JsonReadTask extends AsyncTask<String, Void, String> {
 @Override
 protected String doInBackground(String... params) {
  HttpClient httpclient = new DefaultHttpClient();
  HttpPost httppost = new HttpPost(params[0]);
  nameValuePairs = new ArrayList<NameValuePair>(1); 
  nameValuePairs.add(new BasicNameValuePair("date",perfectdate.toString().trim()));  
 Log.d("sds",perfectdate.toString().trim());
  try {
   httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
   HttpResponse response = httpclient.execute(httppost);
   jsonResult = inputStreamToString(
     response.getEntity().getContent()).toString();
  }

  catch (ClientProtocolException e) {
   e.printStackTrace();
  } catch (IOException e) {
   e.printStackTrace();
  }
  return null;
 }

 private StringBuilder inputStreamToString(InputStream is) {
  String rLine = "";
  StringBuilder answer = new StringBuilder();
  BufferedReader rd = new BufferedReader(new InputStreamReader(is));

  try {
   while ((rLine = rd.readLine()) != null) {
    answer.append(rLine);
   }
  }

  catch (IOException e) {
   // e.printStackTrace();
   Toast.makeText(getActivity(),
     "No events on this date", Toast.LENGTH_LONG).show();
  }
  return answer;
 }

 @Override
 protected void onPostExecute(String result) {
  Listing();
 }
}// end async task

public void accessWebService() {
 JsonReadTask task = new JsonReadTask();
 // passes values for the urls string array
 task.execute(new String[] { url });
}





}

谢谢。

0 个答案:

没有答案