gpt4 book ai didi

java - 当用户选择今天之前的日期时,Android Java 显示错误消息

转载 作者:行者123 更新时间:2023-12-02 12:10:51 25 4
gpt4 key购买 nike

下面是我的 Datepicker 代码,允许用户选择日期并使用所选日期更新 TextView 。当用户选择今天之前的日期时,如何使用错误消息更新 TextView ?

public void startCalender() {

txtTrigger = (TextView) findViewById(R.id.calTrigger);
final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
myCalendar.set(Calendar.DAY_OF_MONTH, day);
myCalendar.set(Calendar.MONTH, month);
myCalendar.set(Calendar.YEAR, year);
updateLabel();
}
};
txtTrigger.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerDialog(DisplayCeeAct.this, date,
myCalendar.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)).show();
}
});
}

private void updateLabel() {
String no = "<font color='red'>NO</font>.";
String myFormat = "dd/MM/yy";
SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.getDefault());

if (myCalendar.after(myCalendar.getTime())){
txtTrigger.setText(sdf.format(myCalendar.getTime()));
}
else {
txtTrigger.setText(Html.fromHtml(no), TextView.BufferType.SPANNABLE);
}
}

最佳答案

这条线似乎崩溃了:

txtTrigger.setText(Html.fromHtml(no), TextView.BufferType.SPANNABLE);

更好的方法是:

txtTrigger.setText("NO");
txtTrigger.setTextColor(Color.RED);

关于java - 当用户选择今天之前的日期时,Android Java 显示错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46559929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com