gpt4 book ai didi

android - 向下滑动时 CalendarView 关闭

转载 作者:行者123 更新时间:2023-11-30 02:12:49 24 4
gpt4 key购买 nike

我正在尝试设置我的日历 View ,但遇到了问题。我设置了 android 标准 CalendarView,它似乎表现正常,但有一个问题。当我向下滑动查看下个月并选择实际日期时, View 关闭。有人可以帮我解决这个问题吗?我想这不是很难解决,但我不能,而且我被困住了。

我在这里做了一切: http://www.thaicreate.com/mobile/android-calendarview.html (第二个例子)甚至在这里: http://androiddhina.blogspot.in/2015/04/android-calender-view.html

这是标准的实现。

最佳答案

事实上,当用户选择新日期或滚动到其他月份时都会调用监听器。

解决方法:

public class CalendarViewActivity extends Activity {

private static final String TAG = CalendarViewActivity.class.getSimpleName();

private int mYear;
private int mMonth;
private int mDay;

private long initialDate;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CalendarView calendar = new CalendarView(this);
calendar.setOnDateChangeListener(mDateSetListener);

// Save initial date of calendar
initialDate = calendar.getDate();

setContentView(calendar);
}

private CalendarView.OnDateChangeListener mDateSetListener = new CalendarView.OnDateChangeListener() {
@Override public void onSelectedDayChange(CalendarView view, int year, int monthOfYear, int dayOfMonth) {

if (view.getDate() == initialDate) {
// Listener called but user have not selected date
return;
}

mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;

view.getDate();

String selectedDate = new StringBuilder().append(mMonth + 1).append("-").append(mDay).append("-")
.append(mYear).append(" ").toString();

Bundle b = new Bundle();
b.putString("dateSelected", selectedDate);

//Add the set of extended data to the intent and start it
Intent intent = new Intent();
intent.putExtras(b);
setResult(RESULT_OK,intent);
finish();
}
};
}

关于android - 向下滑动时 CalendarView 关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29877725/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com