2017-04-12 23 views
1

首先感謝閱讀此:)從Edittext獲取日期到DayDecorator

這是我的問題。

我有一個EditText(用戶數據輸入),我想在我的CustomCalander的那一天使用DayDecorator彩色背景。

//EditText I want to get the date 
huablauf = (EditText)getActivity().findViewById(R.id.huablauf); 



//adding calendar day decorators 

List<DayDecorator> decorators = new ArrayList<>(); 

decorators.add(new Markierung()); 

calendarView.setDecorators(decorators); 

calendarView.refreshCalendar(currentCalendar); 



//class Markierung 

private class Markierung implements DayDecorator { 

EditText huablauf=(EditText)getActivity().findViewById(R.id.huablauf); 

     @Override 
     public void decorate(DayView dayView) { 

     // I know I have to get my String to a date and then get it to 
     // dayView.getDate()! But my code didn´t work 


     dayView.getDate(); 
     int color = Color.parseColor("#f9acb8"); 
     dayView.setBackgroundColor(color); 

     } 

希望您能理解我的問題,任何人都可以幫助:)

THX來自巴伐利亞

+0

沒有你所使用的ListView的添加您calendarview? –

+0

改爲材料壓延視圖 – StefanR

回答

0

試試這個:

@Override 
public void decorate(DayView dayView) { 

    SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy",Locale.getDefault()); 

    try{ 
     if(dayView.getDate().equals(dateFormat.parse(huablauf.getText().toString()))){ 
      int color = Color.parseColor("#f9acb8"); 
      dayView.setBackgroundColor(color); 
     }  
    } catch (Exception e){ 
     //Handle exception. 
    } 
+0

我正要通過與DayDecorator問題去。我剛剛意識到這個問題很古老。可能太老了。 :/ –

+0

該死它不是太舊... :(我把一天的一年的xD –