【发布时间】:2015-10-14 16:08:58
【问题描述】:
屏幕中有一个 CalendarView,我想在同一屏幕上显示选定的日期。我希望它随着用户更改所选日期而动态更改。
这在我的手机 LG G2 中完美运行。每当我在日历中选择一个日期时,它都会显示该日期。但在 Nexus 10 平板电脑中,无论我选择什么日期,它都会返回当天。如果我不断更改日期,则不会发生任何变化,它始终显示当前日期。
这是我的代码的相关部分。
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootview = inflater.inflate(R.layout.calendar_layout, container, false);
calendarView = (CalendarView) rootview.findViewById(R.id.calendarView);
selectedDate = (TextView) rootview.findViewById(R.id.textView5);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener(){
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth){
date = new Date(calendarView.getDate());
dateString = simpleDate.format(date);
MainActivity.selectedDate=dateString;
selectedDate.setText(dateString);
}
});
return rootview;
}
代码有什么问题吗? CalendarView 在手机和平板电脑中的行为不同的原因可能是什么?谢谢你的回答。
【问题讨论】:
标签: java android android-fragments mobile android-studio