首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从编辑文本获取日期到DayDecorator

从编辑文本获取日期到DayDecorator
EN

Stack Overflow用户
提问于 2017-04-12 19:51:37
回答 1查看 258关注 0票数 1

首先,感谢您阅读本文:)

这就是我的问题。

我得到了一个EditText (用户日期输入),我想使用DayDecorator在我的CustomCalander上获得当天的彩色背景。

代码语言:javascript
复制
//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

EN

回答 1

Stack Overflow用户

发布于 2017-07-07 21:37:19

试试这个:

代码语言:javascript
复制
@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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43368762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档