use of android.widget.DatePicker in project xDrip by NightscoutFoundation.
the class BGHistory method setupButtons.
private void setupButtons() {
Button prevButton = (Button) findViewById(R.id.button_prev);
Button nextButton = (Button) findViewById(R.id.button_next);
this.dateButton1 = (Button) findViewById(R.id.button_date1);
this.daysSpinner = (Spinner) findViewById(R.id.daysspinner);
prevButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
date1.add(Calendar.DATE, -noDays);
setupCharts();
}
});
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
date1.add(Calendar.DATE, +noDays);
setupCharts();
}
});
dateButton1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new DatePickerDialog(BGHistory.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
date1.set(year, monthOfYear, dayOfMonth);
setupCharts();
}
}, date1.get(Calendar.YEAR), date1.get(Calendar.MONTH), date1.get(Calendar.DAY_OF_MONTH));
dialog.show();
}
});
String[] vals = new String[14];
vals[0] = 1 + " day";
for (int i = 1; i < vals.length; i++) {
vals[i] = (i + 1) + " days";
}
daysSpinner.setAdapter(new ArrayAdapter(this, android.R.layout.simple_dropdown_item_1line, vals));
daysSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
noDays = position + 1;
setupCharts();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
noDays = 1;
setupCharts();
}
});
}
use of android.widget.DatePicker in project YhLibraryForAndroid by android-coco.
the class YHViewInject method getDateDialog.
/**
* 用于创建PopupWindow封装一些公用属性
*/
// private PopupWindow createWindow(View view, int w, int h, int argb) {
// PopupWindow popupView = new PopupWindow(view, w, h);
// popupView.setFocusable(true);
// popupView.setBackgroundDrawable(new ColorDrawable(argb));
// popupView.setOutsideTouchable(true);
// return popupView;
// }
/**
* 返回一个日期对话框
*/
public void getDateDialog(String title, final TextView textView) {
final String[] time = StringUtils.getDataTime("yyyy-MM-dd").split("-");
final int year = StringUtils.toInt(time[0], 0);
final int month = StringUtils.toInt(time[1], 1);
final int day = StringUtils.toInt(time[2], 0);
DatePickerDialog dialog = new DatePickerDialog(textView.getContext(), new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
textView.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
}
}, year, month - 1, day);
dialog.setTitle(title);
dialog.show();
}
use of android.widget.DatePicker in project bookish-tribble by Hestvik-Dymbe.
the class AddTask method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_task);
summaryView = (EditText) findViewById(R.id.summaryEditText);
descriptionView = (EditText) findViewById(R.id.descriptionEditView);
stakeAmountView = (EditText) findViewById(R.id.stakeAmountEditView);
mDisplayDate = (TextView) findViewById(R.id.dateView);
mDisplayTime = (TextView) findViewById(R.id.timeView);
addButton = (Button) findViewById(R.id.add_button);
mDisplayDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog = new DatePickerDialog(AddTask.this, android.R.style.Theme_Holo_Light_Dialog_MinWidth, mDateSetListener, year, month, day);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.show();
}
});
mDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
month = month + 1;
Log.d(TAG, "onDateSet: mm/dd/yyy: " + month + "/" + day + "/" + year);
monthTime = month;
dayTime = day;
yearTime = year;
String date = day + "/" + month + "/" + year;
mDisplayDate.setText(date);
}
};
// TODO Shows 10:7 instead of 10:07 for example
mDisplayTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Calendar mcurrentTime = Calendar.getInstance();
int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
int minute = mcurrentTime.get(Calendar.MINUTE);
TimePickerDialog mTimePicker;
mTimePicker = new TimePickerDialog(AddTask.this, new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
mDisplayTime.setText(selectedHour + ":" + selectedMinute);
hourTime = selectedHour;
minuteTime = selectedMinute;
}
}, hour, minute, // Yes 24 hour time
true);
mTimePicker.setTitle("Select Time");
mTimePicker.show();
}
});
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
buttonPress();
}
});
}
Aggregations