如何从android中的日期选择器对话框获取列表视图的日期更改?
例如,当它是星期天时,我需要显示“它是假日”,否则列出要显示的视图数据。
edt_date.setText(getTodayDate());
edt_date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setDate(v, edt_date);
}
});
System.out.print(edt_date);
Calendar calendar = Calendar.getInstance();
Date today = calendar.getTime();
String currentdate = dateFormatter1.format(today);
String ourdate = edt_date.getText().toString();
if (ourdate.equals(currentdate)) {
System.out.print("Suc");
Entry_list = (ListView) findViewById(R.id.entry_list_plans);
}
try {
Date date = dateFormatter1.parse(ourdate);
System.out.print(date);
String dow = weekformat.format(date);
System.out.print(dow);
} catch (ParseException e) {
e.printStackTrace();
}
}
//从datepicker对话框设置日期
public void setDate(View view, final EditText edt) {
try {
view.requestFocus();
final DatePickerDialog dpd;
final Calendar c = Calendar.getInstance();
final Calendar cal = Calendar.getInstance();
mYear = c.get(Calendar.YEAR);
mMonth = c.get(Calendar.MONTH);
mDay = c.get(Calendar.DAY_OF_MONTH);
// Launch Date Picker Dialog
DatePickerDialog.OnDateSetListener mDateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
c.set(mYear, mMonth, mDay);
String tmpStr = dateFormatter1.format(c.getTime());
edt.setText(tmpStr);
}
};
dpd = new DatePickerDialog(this,
mDateListener, mYear, mMonth, mDay);
cal.clear();
cal.set(mYear, minMonth, minDay);
dpd.getDatePicker().setMaxDate(new Date().getTime());
dpd.getDatePicker().setMinDate(cal.getTimeInMillis());
dpd.show();
} catch (Exception e) {
Log.d("eEmp/SetDateTime", e.toString());
}
}
答案 0 :(得分:0)
您可以将Calender用于此目的
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
switch (day) {
case Calendar.SUNDAY:
// Current day is Sunday
adapter=new CutomAdapter(items,ListShow.this);///Your List data code here
listView.setAdapter(adapter); ///
case Calendar.MONDAY:
// Current day is Monday
case Calendar.TUESDAY:
// etc.
}
希望这有帮助