Adn*_*Bal 7 android calendar android-custom-view android-calendar calendarview
我正在开发一个日历应用程序,这就是我想做的事情; 例如,我在一个月的不同日期和日历上有各种活动,我想在有活动的日子里添加一个图标(例如音乐会).如果一天没有活动,这一天将没有图标.
注意:我使用CalendarView作为日历UI.
这是我想要解释的图像;
http://postimage.org/image/kdejw72nb/
请帮助我在这个特殊的日子里添加这个小图标.
提前致谢.
您必须创建自定义 gridView。它可能看起来像这样:
工作日的布局
<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" />
Run Code Online (Sandbox Code Playgroud)
这几天的layout.xml
<GridView
android:id="@+id/days"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:numColumns="7" />
Run Code Online (Sandbox Code Playgroud)
显示工作日的java代码
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;
}
}
Run Code Online (Sandbox Code Playgroud)
您可以执行类似的操作来设置该月的日期。随意问任何问题。