Android: date picker using xml layout

I tried to display the date picker using xml code. But nothing seemed. Is it possible to display DatePicker only through java code?

datePickerExample.java

public class datePickerExample extends Activity
{
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.date_picker_example); 
    }
}

date_picker_example.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/lay_main"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bg" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Date : " >
    </TextView>

    <DatePicker
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:endYear="2100"
        android:startYear="1900" >
    </DatePicker>

</LinearLayout>

Thank...

+3
source share
1 answer

Add this attribute:

android:orientation="vertical"

in the LinearLayout element, and the date picker appears.

+3
source

Source: https://habr.com/ru/post/1777393/


All Articles