1

我需要 DatePicker 在旋转到今天时说“今天”而不是今天的日期。我该怎么做?我的 DatePicker 小部件配置如下 -

    <DatePicker android:id="@+id/dueDatePicker"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="130dp"
            android:layout_marginRight="80dp"
            android:gravity="center_horizontal"
/>
4

1 回答 1

0

此代码应向您展示一般方法:

DatePicker datePicker = (DatePicker) findViewById(R.id.dueDatePicker);
OnDateChangedListener listener = new OnDateChangedListener() {

    @Override
    public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
        // Check if its the current date. isCurrentDate() is not a standard method! you have to implement it by yourself! 
        if(isCurrentDate(dayOfMonth, monthOfYear, year)) {
            // Here you can do whatever you want, if its the current date.
            view.setTitle("Today");
        }
    }
};
datePicker.init (day, month, year, listener); 

我希望这能有所帮助 ;)

于 2013-09-05T21:42:33.403 回答