我正在尝试在material-calendarView上设置日期。我有3个变量,分别是年,月和日,我希望屏幕显示带有日期标记的日历,即月和年。我不想选择一个日期,但是我希望该日期自动出现在日历上,换句话说,这三个变量必须在日历上产生,并带有年,月和日。
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import com.prolificinteractive.materialcalendarview.CalendarDay;
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
import java.util.Calendar;
public class BlankFragment6_tela2 extends Fragment {
private MaterialCalendarView calendarView;
public BlankFragment6_tela2() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_blank_fragment6_tela2, container, false);
Bundle args = getArguments();
if (args != null) {
int datareceived = args.getInt("dataDia", 0);
int datareceived1 = args.getInt("dataMes", 0);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, 2019);
calendar.set(Calendar.MONTH, (datareceived1 - 1));
calendar.set(Calendar.DAY_OF_MONTH, datareceived);
calendarView = view.findViewById(R.id.calendarViewId);
calendarView.setSelectedDate(CalendarDay.from(2019,datareceived1,datareceived));
}
return view;
}
}