如何在Android CalendarView上仅显示特定月份? [英] How to show only a specific month on Android CalendarView?
问题描述
我想在CardView上显示特定月份,没有,请使用NEXT和PREVIOUS箭头导航日历.如果要显示2010年2月的信息,则用户只能看到2010年2月的信息.他们不能去下个月或上个月.
I want to show a specific month on CardView without NEXT and PREVIOUS arrow to navigate the calendar. If I want to show February 2010 user must see only February 2010. They can't go next or previous month.
我遵循了此堆栈溢出答案,以显示特定月份,但对我来说不起作用.它始终显示我案件的当前日期和月份.我不确定是否可以禁用下一个上一个导航.
I followed this Stack Overflow answer to show a specific month but it's not working for me. It shows all time the current date and month for my case. I'm not sure is it possible or not to disable NEXT-PREVIOUS navigation.
我的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="megaminds.dailyeditorialword.Fragments.CalendarViewFragment">
<CalendarView
android:id="@+id/calendarViewT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:firstDayOfWeek="7">
</CalendarView>
onCreateView
:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_calendar_view, container, false);
int year = 2010, month = 2, day = 1;
CalendarView calendarView = (CalendarView) view.findViewById(R.id.calendarViewT);
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day); //want to show full month of February 2010
calendarView.setMinDate(calendar.getTimeInMillis());
return view;
}
我如何只显示2月月份而没有上一个上一个导航?
How can I show only February month without next-previous navigation?
推荐答案
Calendar febFirst=Calendar.getInstance();
febFirst.set(2017, 1, 1, 0, 0, 0);
calendar.setMinDate(febFirst.getTimeInMillis());
Calendar febLast=Calendar.getInstance();
febLast.set(2017, 2, 0, 0, 0, 0);
calendar.setMaxDate(febLast.getTimeInMillis());
calendar.setDate(febFirst.getTimeInMillis());
其中calendar
是CalendarView
.
这篇关于如何在Android CalendarView上仅显示特定月份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!