Это код, который был опробован. В настоящее время он получает текущую дату и время, а не выбор пользователей из средств выбора.
Это средства выбора ниже:
Код: Выделить всё
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.create_line);
myDb = new DatabaseHelper(this);
quantity = (TextView) findViewById(R.id.editText3);
duration = (TextView) findViewById(R.id.durationtextView);
dateButton = (Button) findViewById(R.id.angry_btn);
VerifyButton = (Button) findViewById(R.id.confirmButton);
tv = (Button) findViewById(R.id.buttonddate);
mCurrentDate = Calendar.getInstance();
day = mCurrentDate.get(Calendar.DAY_OF_MONTH);
month = mCurrentDate.get(Calendar.MONTH);
year = mCurrentDate.get(Calendar.YEAR);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DatePickerDialog datePickerDialog = new DatePickerDialog(CreateLine.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
monthOfYear = monthOfYear +1;
String Sd = String.valueOf(dayOfMonth + "/" + monthOfYear + "/" + year);
tv.setText(Sd);
}
}, year, month, day);
datePickerDialog.show();
}
});
display = (Button) findViewById(R.id.button_displayTPD);
Button displayTDPButton = (Button) findViewById(R.id.button_displayTPD);
displayTDPButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new TimePickerDialog(CreateLine.this, onTimeSetListener, calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), true).show();
}
TimePickerDialog.OnTimeSetListener onTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
String St = String.valueOf(hourOfDay + ":" + minute);
display.setText(St);
}
};
Код: Выделить всё
dateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dateButton.setText(date.toString());
// Creates an instance of current DateTime which represents the
// current date time.
//DateTime dateTime = new DateTime();
DateTime dateTime = new DateTime(year, month, day, 12, 0, 0, 11);
DateTimeFormatter fmt = DateTimeFormat.forPattern("E d MMM yyyy" + "\n" + " h:mm a ");
String formattedtime = fmt.print(dateTime);
dateButton.setText(formattedtime);
// Plus some hours, minutes, and seconds to the original DateTime.
DateTimeFormatter fmt2 = DateTimeFormat.forPattern("E d MMM yyyy" + "\n" + " h:mm a ");
DateTime dateTime1 = dateTime.plusHours(timeadded);
String endtimecalc = fmt2.print(dateTime1);
TextView endtime = (TextView) findViewById(endtimetextView);
endtime.setText(endtimecalc);
}
});
VerifyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String spinnerSelection = String.valueOf(spinner.getSelectedItem());
String spinnerSelection2 = String.valueOf(spinner2.getSelectedItem());
String q = quantity.getText().toString();
String d = duration.getText().toString();
DateTime dateTime = new DateTime();
DateTimeFormatter fmt = DateTimeFormat.forPattern("E d MMM yyyy" + "\n" + " h:mm a ");
String formattedtime = fmt.print(dateTime);
dateButton.setText(formattedtime);
// Plus some hours, minutes, and seconds to the original DateTime.
DateTimeFormatter fmt2 = DateTimeFormat.forPattern("E d MMM yyyy" + "\n" + " h:mm a ");
DateTime dateTime1 = dateTime.plusHours(timeadded);
String endtimecalc = fmt2.print(dateTime1);
TextView endtime = (TextView) findViewById(endtimetextView);
endtime.setText(endtimecalc);
[img]https://i. sstatic.net/0kcO5.png[/img]
Подробнее здесь: https://stackoverflow.com/questions/469 ... me-pickers
Мобильная версия