[英]How do I display a CalendarView in an AlertDialog?
我正在尝试在警报对话框中显示CalendarView,但显示的所有内容都是月/年和星期几。 这些是布局文件的内容:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<CalendarView
android:id="@+id/calendarID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/cal_desc"
android:maxDate="01/01/2013"
android:minDate="09/01/2012"
android:showWeekNumber="false"
android:tag="my tag" />
</LinearLayout>
这是我用于将布局添加到AlertDialog的代码:
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout ll= (LinearLayout)inflater.inflate(R.layout.myLayout, null, false);
CalendarView cv = (CalendarView) ll.getChildAt(0);
cv.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month,
int dayOfMonth) {
// TODO Auto-generated method stub
initScheduleEvent();
}
});
new AlertDialog.Builder(MomAppActivity.this)
.setTitle("Event Calendar")
.setMessage("Click to schedule or view events.")
.setView(ll)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//do nothing...yet
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
}
).show();
任何帮助将非常感谢,因为我完全难过。 该应用程序不会给我任何错误继续。
正确显示日历需要最小高度。 其余代码工作正常。
如果要为对话框定制设计,可以使用布局和窗口小部件元素为对话框窗口创建自己的布局。
试试这些链接希望你找到答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.