如何从 android TimeSquare 库中获取选定的日期?
How to get the selected date from android TimeSquare library?
如何从 android TimeSquare 库中获取用户 selected 日期?
我使用了 getselectedate() 但它没有用,OnClickListener 也没有用这个。
public class HomeActivity extends Activity {
private String dateHolder;
private CalendarPickerView calenderView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
calenderView = (CalendarPickerView) findViewById(R.id.calendar_view);
calenderView.init(lastYear.getTime(), nextYear.getTime())
.inMode(SelectionMode.SINGLE)
.withSelectedDate(new Date());
TextView tv = (TextView)findViewById(R.id.calendar_view);
tv.setText("Pickup Date:" + **HOW_TO_PRINT_SELECTED_DATE_HERE** );
}
}
在上面的代码示例中,我必须在 TextView 电视 (HOW_TO_PRINT_SELECTED_DATE_HERE) 中显示 PickUpDate,一旦用户 select 日期来自日历。
这是我的答案:
calenderView.setOnDateSelectedListener(new OnDateSelectedListener() {
@Override
public void onDateUnselected(Date date) {
}
@Override
public void onDateSelected(Date date) {
Toast.makeText(HomeActivity.this,calenderView.getSelectedDate().getTime()+"", Toast.LENGTH_LONG).show();
tv.setText("Pickup Date:" +calenderView.getSelectedDate().getTime());
}
});
这是我的回答
CalendarPickerView datePicker;
Date today = new Date();
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
datePicker = findViewById(R.id.calendar);
datePicker.init(today, nextYear.getTime())
.inMode(CalendarPickerView.SelectionMode.RANGE)
.withSelectedDate(today);
datePicker.setOnDateSelectedListener(new CalendarPickerView.OnDateSelectedListener() {
@Override
public void onDateSelected(Date date) {
//String selectedDate = DateFormat.getDateInstance(DateFormat.FULL).format(date);
Calendar calSelected = Calendar.getInstance();
calSelected.setTime(date);
String selectedDate = "" + calSelected.get(Calendar.DAY_OF_MONTH)
+ "-" + (calSelected.get(Calendar.MONTH) + 1)
+ "-" + calSelected.get(Calendar.YEAR);
Toast.makeText(timesquare.this, selectedDate, Toast.LENGTH_SHORT).show();
dialog(selectedDate);
}
@Override
public void onDateUnselected(Date date) {
}
});
calendar.setOnDateSelectedListener(new CalendarPickerView.OnDateSelectedListener()
{
@Override
public void onDateSelected(Date date)
{
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy", Locale.ENGLISH);
tv.setText("Pickup Date:" +dateFormat.format(date));
}
@Override
public void onDateUnselected(Date date)
{
}
});
如何从 android TimeSquare 库中获取用户 selected 日期? 我使用了 getselectedate() 但它没有用,OnClickListener 也没有用这个。
public class HomeActivity extends Activity {
private String dateHolder;
private CalendarPickerView calenderView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
calenderView = (CalendarPickerView) findViewById(R.id.calendar_view);
calenderView.init(lastYear.getTime(), nextYear.getTime())
.inMode(SelectionMode.SINGLE)
.withSelectedDate(new Date());
TextView tv = (TextView)findViewById(R.id.calendar_view);
tv.setText("Pickup Date:" + **HOW_TO_PRINT_SELECTED_DATE_HERE** );
}
}
在上面的代码示例中,我必须在 TextView 电视 (HOW_TO_PRINT_SELECTED_DATE_HERE) 中显示 PickUpDate,一旦用户 select 日期来自日历。
这是我的答案:
calenderView.setOnDateSelectedListener(new OnDateSelectedListener() {
@Override
public void onDateUnselected(Date date) {
}
@Override
public void onDateSelected(Date date) {
Toast.makeText(HomeActivity.this,calenderView.getSelectedDate().getTime()+"", Toast.LENGTH_LONG).show();
tv.setText("Pickup Date:" +calenderView.getSelectedDate().getTime());
}
});
这是我的回答
CalendarPickerView datePicker;
Date today = new Date();
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
datePicker = findViewById(R.id.calendar);
datePicker.init(today, nextYear.getTime())
.inMode(CalendarPickerView.SelectionMode.RANGE)
.withSelectedDate(today);
datePicker.setOnDateSelectedListener(new CalendarPickerView.OnDateSelectedListener() {
@Override
public void onDateSelected(Date date) {
//String selectedDate = DateFormat.getDateInstance(DateFormat.FULL).format(date);
Calendar calSelected = Calendar.getInstance();
calSelected.setTime(date);
String selectedDate = "" + calSelected.get(Calendar.DAY_OF_MONTH)
+ "-" + (calSelected.get(Calendar.MONTH) + 1)
+ "-" + calSelected.get(Calendar.YEAR);
Toast.makeText(timesquare.this, selectedDate, Toast.LENGTH_SHORT).show();
dialog(selectedDate);
}
@Override
public void onDateUnselected(Date date) {
}
});
calendar.setOnDateSelectedListener(new CalendarPickerView.OnDateSelectedListener()
{
@Override
public void onDateSelected(Date date)
{
SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy", Locale.ENGLISH);
tv.setText("Pickup Date:" +dateFormat.format(date));
}
@Override
public void onDateUnselected(Date date)
{
}
});