Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add icon or change calendarview's day icon?

I'm developing a calendar application and here's what i want to do; for example, i have various activities in various days of a month and on the calendar, i want to add an icon to days which have activity(a concert for example). if a day does not have an activity this day will not have an icon.

Note: I'm using CalendarView as calendar UI.

Here's the image what i'm trying to explain ;

http://postimage.org/image/kdejw72nb/

Please help me to add this tiny icons to this spesific days.

Thanks in advance.

like image 323
Adnan Bal Avatar asked Oct 21 '12 20:10

Adnan Bal


1 Answers

You would have to create your custom gridView. It could look something like this :

layout for the weekdays

<GridView
    android:id="@+id/weekdays"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:clickable="false"
    android:numColumns="7" />

layout.xml for the days

<GridView
    android:id="@+id/days"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:numColumns="7" />

java code for displaying the weekdays

GridView weekdays = (GridView) linearLayout.findViewById(R.id.weekdays);
weekdays.setAdapter(new Weekdays());


public class WeekDays extends BaseAdapter {
String[] weekdays = null;

public WeekDayAdapter() {
  DateFormatSymbols dateFormatSymbols= new DateFormatSymbols();

  weekdays = = dateFormatSymbols.getShortWeekdays();
}

public int getCount() {
  return 7;
}

public Object getItem(int position) {
  return weekdays[position];
}

public long getItemId(int position) {
  return GridView.INVALID_ROW_ID;
}

public View getView(int position, View convertView, ViewGroup parent) {
  View view = null;

  view = new LinearLayout(parent.getContext());
  view.setLayoutParams(new GridView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
  view.setOrientation(Horizontal);

  LinearLayout linearLayout = new LinearLayout(parent.getContext());
  linearLayout.setOrientation(Vertical);

  TextView weekDays = new TextView(parent.getContext());
  weekDays.setText(weekdays[position + 1]);

  linearLayout.addView(weekDays);

  view.addView(linearLayout);

  return view;
}
}

You could do something similar for setting the days of the month. Feel free to ask any questions.

like image 86
lokoko Avatar answered Oct 21 '22 20:10

lokoko