Reputation: 276
I have a TimePicker in a Dialog. But what I want is to initiate it with value that I chose and not with current time. I don't know how to do it.
Here is my Java code :
public void showTimePickerDialog(View v) {
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.reminder_edit);
View view = getLayoutInflater().inflate(R.layout.reminder_edit, null);
dialog.setTitle("Fréquence des notifications");
timepicker = (TimePicker) view.findViewById(R.id.timePicker1);
timepicker.setIs24HourView(true);
int hour =2;
timepicker.setCurrentHour(hour);
timepicker.setCurrentMinute(0);
dialog.show();
}
Here is my XML code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</TimePicker>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Annuler" />
<Button
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ok" />
</LinearLayout>
Upvotes: 0
Views: 47
Reputation: 113
You are creating the dialog and assigning it the view. But then you inflate a new view and manipulate the contents. To actually change the TimePicker owned by the dialog you will have to retrieve it.
timepicker picker = (TimePicker) dialog.findViewById(R.id.timePicker1);
Upvotes: 1