Domanda

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.

È stato utile?

Soluzione

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.

Altri suggerimenti

Another alternative is to use the CalendarProvider. You could refer to this : http://developer.android.com/guide/topics/providers/calendar-provider.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top