diff --git a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/widget/WheelDayPicker.java b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/widget/WheelDayPicker.java index 91265446..7663c6db 100644 --- a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/widget/WheelDayPicker.java +++ b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/widget/WheelDayPicker.java @@ -2,6 +2,7 @@ import android.content.Context; import android.support.annotation.NonNull; +import android.text.TextUtils; import android.util.AttributeSet; import com.github.florent37.singledateandtimepicker.DateHelper; @@ -22,6 +23,8 @@ public class WheelDayPicker extends WheelPicker { private OnDaySelectedListener onDaySelectedListener; + private String todayText; + public WheelDayPicker(Context context) { super(context); } @@ -40,11 +43,6 @@ protected String initDefault() { return getTodayText(); } - @NonNull - private String getTodayText() { - return getResources().getString(R.string.picker_today); - } - public WheelDayPicker setDayFormatter(SimpleDateFormat simpleDateFormat){ this.simpleDateFormat = simpleDateFormat; adapter.setData(generateAdapterValues()); @@ -126,11 +124,21 @@ private Date convertItemToDate(int itemPosition) { return date; } + public int getTodayTextPosition() { + return adapter.getData().indexOf(getTodayText()); + } + + @NonNull + private String getTodayText() { + return TextUtils.isEmpty(todayText) ? getResources().getString(R.string.picker_today) : todayText; + } + public void setTodayText(String todayText) { - int index = adapter.getData().indexOf(getTodayText()); + int index = getTodayTextPosition(); if (index != -1) { adapter.getData().set(index, todayText); notifyDatasetChanged(); + this.todayText = todayText; } } diff --git a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/widget/WheelPicker.java b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/widget/WheelPicker.java index f2407828..3ca87546 100644 --- a/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/widget/WheelPicker.java +++ b/singledateandtimepicker/src/main/java/com/github/florent37/singledateandtimepicker/widget/WheelPicker.java @@ -927,7 +927,7 @@ public int findIndexOfDate(@NonNull Date date) { if (this instanceof WheelDayPicker) { String today = getFormattedValue(new Date()); if (today.equals(formatItem)) { - return getDefaultItemPosition(); + return ((WheelDayPicker)this).getTodayTextPosition(); } }