Domanda

I'm trying to display the CalendarView in an Alert Dialog, but all that shows up is the month/year and the days of the week. These are the contents of the layout file:

<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>

This is the code I used to add the layout to an 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();

Any help would be greatly appreciated seeing as I am completely stumped. The application isn't giving me any errors to go on.

È stato utile?

Soluzione

A minimum height was required for the calendar to show up properly. The rest of the code worked fine.

Altri suggerimenti

If you want a customized design for a dialog, you can create your own layout for the dialog window with layout and widget elements.

try these links hope you find your answer

  1. http://www.mkyong.com/android/android-custom-dialog-example/

  2. http://developer.android.com/guide/topics/ui/dialogs.html

  3. http://www.helloandroid.com/tutorials/how-display-custom-dialog-your-android-application

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top