Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- adapter class
- public View getView(int position, View convertView, ViewGroup parent) {
- View v = convertView;
- TextView dayView;
- if (convertView == null) { // if it's not recycled, initialize some
- // attributes
- LayoutInflater vi = (LayoutInflater) mContext
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- v = vi.inflate(R.layout.calendar_item, null);
- }
- dayView = (TextView) v.findViewById(R.id.date);
- // separates daystring into parts.
- String[] separatedTime = dayString.get(position).split("-");
- // taking last part of date. ie; 2 from 2012-12-02
- String gridvalue = separatedTime[2].replaceFirst("^0*", "");
- // checking whether the day is in current month or not.
- if ((Integer.parseInt(gridvalue) > 1) && (position < firstDay)) {
- // setting offdays to white color.
- dayView.setTextColor(Color.WHITE);
- dayView.setClickable(false);
- dayView.setFocusable(false);
- } else if ((Integer.parseInt(gridvalue) < 7) && (position > 28)) {
- dayView.setTextColor(Color.WHITE);
- dayView.setClickable(false);
- dayView.setFocusable(false);
- } else {
- // setting curent month's days in black color.
- dayView.setTextColor(Color.BLACK);
- }
- if (dayString.get(position).equals(curentDateString)) {
- setSelected(v);
- previousView = v;
- } else {
- v.setBackgroundResource(R.drawable.list_item_background);
- // v.setBackgroundResource(Integer.parseInt("#64DD17"));
- }
- dayView.setText(gridvalue);
- // create date string for comparison
- String date = dayString.get(position);
- if (date.length() == 1) {
- date = "0" + date;
- }
- String monthStr = "" + (month.get(GregorianCalendar.MONTH) + 1);
- if (monthStr.length() == 1) {
- monthStr = "0" + monthStr;
- }
- if((position==0 || position==7 || position==14 || position==21 || position==28 || position==35)) {
- dayView.setTextColor(Color.RED);
- }
- // show icon if date is not empty and it exists in the items array
- ImageView iw = (ImageView) v.findViewById(R.id.date_icon);
- //iw.setBackgroundResource(R.drawable.calendar_cel_select3);
- iw.setImageResource(R.drawable.calendar_cel_select3);
- //textView2= (TextView) v.findViewById(R.id.evntnm);
- textView= (TextView) v.findViewById(R.id.date);
- // ViewGroup viewGroup=(ViewGroup) v.getParent();
- if (date.length() > 0 && items != null && items.contains(date)) {
- iw.setVisibility(View.VISIBLE);
- // viewGroup.removeView(iw);
- v.setBackgroundColor(Color.parseColor("#00695C"));
- //textView2.setVisibility(View.VISIBLE);
- //textView.setBackgroundResource(R.drawable.calendar_cel_select3);
- //textView.setBackgroundResource(R.drawable.calendar_cel_select3);
- // textView.setBackgroundColor(Color.parseColor("#rrggbb"));
- textView.setVisibility(View.VISIBLE);
- textView.setDrawingCacheBackgroundColor(Color.parseColor("#1DE9B6"));
- } else {
- // viewGroup.addView(iw);
- iw.setVisibility(View.INVISIBLE);
- //textView2.setVisibility(View.INVISIBLE);
- textView.setVisibility(View.VISIBLE);
- }
- return v;
- }
- public View setSelected(View view) {
- if (previousView != null) {
- previousView.setBackgroundResource(R.drawable.list_item_background);
- //view.setBackgroundColor(Integer.parseInt("#64DD17"));
- //view.setBackgroundResource(R.drawable.calendar_cel_select3);
- }
- previousView = view;
- view.setBackgroundResource(R.color.colorPrimary);
- return view;
- }
- mainactivity adding to arraylist
- public Runnable calendarUpdater = new Runnable() {
- DataDisplayActivity dataDisplayActivity=new DataDisplayActivity();
- @Override
- public void run() {
- items.clear();
- // Print dates of the current week
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
- String itemvalue;
- for (int i = 0; i < 7; i++) {
- itemvalue = df.format(itemmonth.getTime());
- itemmonth.add(GregorianCalendar.DATE, 1);
- items.add("2016-05-03");
- adapter.setItems(items);
- adapter.notifyDataSetChanged();
- }
- retriving data
- try {
- JSONArray jsonArray = new JSONArray(data);
- for(int i=0;i<jsonArray.length();i++) {
- JSONObject jsonObject = jsonArray.getJSONObject(i);
- date = jsonObject.getString("startdt");
- String toTime = jsonObject.getString("enddt");
- /* String fromTime = jsonObject.getString("");
- String seats = jsonObject.getString("");
- String venue = jsonObject.getString("");
- String address = jsonObject.getString("");*/
- data += "Node"+i+" : \n id= "+ date +" \n Name= "+ toTime +"" ;
- textView1.setText(date);
- textView2.setText(toTime);
- }
- if(data!=null && data.equals(CalendarAdapter.getMaxP())) {
- {
- CalendarAdapter.dayString.add(date);
- }
Add Comment
Please, Sign In to add comment