8

Tôi đang cố gắng hiển thị CalendarView trong Hộp thoại cảnh báo, nhưng tất cả hiển thị là tháng/năm và các ngày trong tuần. Đây là những nội dung của file layout:Làm cách nào để hiển thị CalendarView trong AlertDialog?

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

Đây là mã tôi sử dụng để thêm cách bố trí để một 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(); 

Bất kỳ trợ giúp sẽ được đánh giá cao khi nhìn thấy như tôi hoàn toàn bối rối . Ứng dụng không cho tôi bất kỳ lỗi nào để tiếp tục.

Trả lời

6

Một chiều cao tối thiểu được yêu cầu cho lịch để hiển thị đúng cách. Phần còn lại của mã hoạt động tốt.

+0

Tôi tìm thấy một câu trả lời cụ thể hơn tại http://stackoverflow.com/a/7033869/94148 – aleung

0

Nếu bạn muốn thiết kế tùy chỉnh cho hộp thoại, bạn có thể tạo bố cục của riêng mình cho cửa sổ hộp thoại với phần tử bố cục và tiện ích con.

thử những liên kết này hy vọng bạn tìm thấy câu trả lời của bạn

  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

Các vấn đề liên quan