Coder Social home page Coder Social logo

添加文字 about datepicker HOT 1 CLOSED

lastzhou avatar lastzhou commented on August 23, 2024
添加文字

from datepicker.

Comments (1)

ycuwq avatar ycuwq commented on August 23, 2024

添加文字使用setDataFormat处理 类似 #9
这种情况可以使用自定义format 例如:

DatePicker datePicker = findViewById(R.id.datePicker);
datePicker.getDayPicker().setVisibility(View.GONE);
datePicker.setMaxDate(System.currentTimeMillis());
Calendar calendar = Calendar.getInstance();
int currentYear = calendar.get(Calendar.YEAR);
int currentMonth = calendar.get(Calendar.MONTH) + 1;
Format monthFormat = new Format() {
    @NonNull
    @Override
    public StringBuffer format(Object obj,
                               StringBuffer toAppendTo,
                               FieldPosition pos) {
        int month;
        if (obj instanceof Number) {
            month = ((Number) obj).intValue();
        } else {
            month = Integer.parseInt(obj.toString());
        }
        return datePicker.getYear() == currentYear && currentMonth == month ? new StringBuffer("至今") : new StringBuffer(String.valueOf(month));
    }

    @Override
    public Object parseObject(String source, ParsePosition pos) {
        return null;
    }

};
datePicker.getMonthPicker().setDataFormat(monthFormat);

from datepicker.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.