Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Date Picker using xml layout

I tried to display date picker using xml code. But it did not display anything. Can I 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 you...

like image 538
Jomia Avatar asked Oct 14 '22 20:10

Jomia


1 Answers

Add this attribute:

android:orientation="vertical"

in your LinearLayout element and the date-picker will appear.

like image 196
kgiannakakis Avatar answered Oct 19 '22 23:10

kgiannakakis