I'm writing an app where I need to get the user set time from the start time time picker, and a user set time from an end time time picker. Then compare the start time and the end time with the current time. If the current time equals the start time the silence the phone. If the end time equals the current time un-silence the phone. Any help, especially code examples would be greatly appreciated. Thanks ahead of time.
public TimePickerDialog.OnTimeSetListener sTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
sHour = hourOfDay;
sMinute = minute;
updateDisplay();
displayToast();
}
};
public TimePickerDialog.OnTimeSetListener eTimeSetListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
eHour = hourOfDay;
eMinute = minute;
updateDisplayE();
displayToastE();
}
};
public void updateDisplay() {
startTime.setText(new StringBuilder().append(pad(sHour)).append(":")
.append(pad(sMinute)));
final int compareStartHour = sHour;
Log.e("beginning", "Value " + sHour);
}
public void updateDisplayE()
{
endTime.setText(new StringBuilder().append(pad(eHour)).append(":")
.append(pad(eMinute)));
}
private void displayToast() {
Toast.makeText(
this,
new StringBuilder().append("Time choosen is ").append(
startTime.getText()), Toast.LENGTH_SHORT).show();
}
private void displayToastE() {
Toast.makeText(
this,
new StringBuilder().append("Time choosen is ").append(
endTime.getText()), Toast.LENGTH_SHORT).show();
}
private static String pad(int c) {
if (c >= 10)
return String.valueOf(c);
else
return "0" + String.valueOf(c);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preset_edit);
save = (Button) findViewById(R.id.btnSave);
TextView eventTxt = (TextView) findViewById(R.id.txtViewEvent);
startTime = (Button) findViewById(R.id.btnStartTime);
endTime = (Button) findViewById(R.id.btnEndTime);
startTime.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(TIME_DIALOG_ID);
}
});
endTime.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(TIME_DIALOG_ID2);
}
});