Reputation: 7407
I want to add the time and the date picker of Android in my main view and display it always. Now it works only as a dialog. Is there any way to use it as a view and not a dialog?
Is there any library that can do that?
Thanks in advance
Upvotes: 1
Views: 2849
Reputation: 13555
Try this way..this is the way you can create without dailog
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_vertical">
<TimePicker
android:id="@+id/picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
TimePickerDemoActivity.java
public class TimePickerDemoActivity extends Activity implements
OnTimeChangedListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TimePicker picker=(TimePicker)findViewById(R.id.picker);
picker.setOnTimeChangedListener(this);
}
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
Calendar then=Calendar.getInstance();
then.set(Calendar.HOUR_OF_DAY, hourOfDay);
then.set(Calendar.MINUTE, minute);
then.set(Calendar.SECOND, 0);
Toast.makeText(this, then.getTime().toString(), Toast.LENGTH_SHORT)
.show();
}
}
Upvotes: 3
Reputation: 2828
You can add date picker and time picker in your layout
<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
you can set them according to your requirments
Upvotes: 6