import android.app.Activity;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;
public class DateView extends Activity {
/** Called when the activity is first created. */
TimePicker tp;
DatePicker dp;
Button b1;
int hour,minute;
static final int timeid=0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tp=(TimePicker)findViewById(R.id.timePicker1);
tp.setIs24HourView(true);
dp=(DatePicker)findViewById(R.id.datePicker1);
b1=(Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(),"Dateselected"+dp.getDayOfMonth()+"/"+dp.getMonth()+1+"/"+dp.getYear()
+"\n"+"time selected"+tp.getCurrentHour()+":"+tp.getCurrentMinute(),Toast.LENGTH_LONG).show();
//showDialog(timeid);
}
});
}
protected Dialog onCreateDialog(int id)
{
switch (id) {
case timeid:
return new TimePickerDialog(
this, mTimeSetListener, hour, minute, false);
}
return null;
}
private TimePickerDialog.OnTimeSetListener mTimeSetListener =
new TimePickerDialog.OnTimeSetListener()
{
public void onTimeSet(
TimePicker view, int hourOfDay, int minuteOfHour)
{
hour = hourOfDay;
minute = minuteOfHour;
Toast.makeText(getBaseContext(),
"you have selected"+hour+":"+minute,
Toast.LENGTH_SHORT).show();
}
};
}
No comments:
Post a Comment