小编Pla*_*l89的帖子

如何在AlertDialog中显示CalendarView?

我正在尝试在警报对话框中显示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>
Run Code Online (Sandbox Code Playgroud)

这是我用于将布局添加到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) …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-layout android-alertdialog calendarview

8
推荐指数
1
解决办法
1万
查看次数