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_w开发者_Python百科idth="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...
Add this attribute:
android:orientation="vertical"
in your LinearLayout element and the date-picker will appear.
精彩评论