2015-06-22 83 views
2

我是剛剛開發android並開始開發預訂應用程序。有一個日曆視圖,我想禁用該日曆中的預訂日期。我發現在Android默認日曆中沒有禁用功能。所以你可以幫我找到一個很好的自定義日曆視圖,可以禁用特定的日期。我需要一個資源或一個圖書館。謝謝!Android自定義日曆視圖禁用特定日期

+0

嘗試這些鏈接:HTTP://www.androiddevelopersolutions.com/2013/05/android-calendar-sync.html HTTPS: //abinashandroid.wordpress.com/2013/07/21/how-to-create-custom-calendar-in-android/ – Srijith

回答

3

將CalendarPickerView包含在佈局XML中。

<com.squareup.timessquare.CalendarPickerView 
android:id="@+id/calendar_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent"/> 

在您的活性/對話框的onCreate或者片段的onCreateView,初始化與一系列有效的日期以及當前選擇的日期的圖。

Calendar nextYear = Calendar.getInstance(); 
nextYear.add(Calendar.YEAR, 1); 

CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view); 
Date today = new Date(); 
calendar.init(today, nextYear.getTime()).withSelectedDate(today); 

enter image description here

github上鍊路https://github.com/square/android-times-square

+0

Thanx夥計。這將幫助我! – user2214782

+0

歡迎夥伴:) – Gattsu

+0

你使用過這個日曆嗎?有一種突出顯示日期但禁用日期的方法。任何我可以做的禁用日期,以便用戶不能拿起那些禁用的日子! – user2214782

0
i have faced the same problem using custom calendar , 
i just overridden the function of adapter 


@Override 
    public boolean isEnabled(int position) { 
     if(mySet.contains(position)) 
      return true; 
     else 
      return false; 
    } 


then i call the function int the adapter view 

isEnabled(position); 




befoer that tale Hashset and add the position which is displaying the calanderview 


      // mysetSize=set.size(); 
      //isEnabled(Integer.parseInt(gridvalue)); 
      Log.d(dayView.getTag()+"------1-------"+gridvalue,"-------"+position); 
     } else if ((Integer.parseInt(gridvalue) < 7) && (position > 28)) { 
      dayView.setTextColor(Color.WHITE); 
      dayView.setClickable(false); 
      dayView.setFocusable(false); 
      Log.d("-------mySet------","-------"+mySet); 
      Log.d(mysetSize+"-------28------"+gridvalue,"-------"+position); 
      set.add(position); 

     } else { 
      // setting curent month's days in blue color. 
      dayView.setTextColor(Color.DKGRAY); 
      Log.d(dayView.getTag()+"-------current display post------","-------"+position); 
      mySet.add(position); 
     }