Tell me how to work with time and date, if I want to set the time on the activation form, and not through a separate widget
- The question is not clear. Do you want to implement independently the functionality of the dialogue inside your view, without causing the dialogue? - stanislav
- Yes, I threw in the constructor on the form (activit), these 2 widgets (dates and time), but how to access them, that I would have no idea what to take from them)) - Gorets
|
2 answers
Usually do so. Add a button to the view:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"> <Button android:id="@+id/chooseTimeButton" android:text="Выбрать время"/> </LinearLayout>
And add a handler to the code
public class Sample extends Activity { private Button chooseTimeButton; static final int TIME_DIALOG_ID = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); chooseTimeButton = (Button)findViewById(R.id.chooseTimeButton); chooseTimeButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showDialog(TIME_DIALOG_ID); } }); } private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hour, int minute) { // TODO: А вот здесь использовать полученные значения часов и минут } }; @Override protected Dialog onCreateDialog(int id) { switch (id) { case TIME_DIALOG_ID: return new TimePickerDialog(this, mTimeSetListener, 0, 0, false); } return null; } }
If you want to insert the contents of the dialog directly into the view, the easiest way to copy the necessary one from the source of the dialogue.
|