Alex Rivera | Logout

Android: How to get values from date and time picker

Asked 2012-04-27T07:41:29.030
9

I am building a app in which i am trying to ask user to select the time, so i used datePicker and timePicker and a button set. So when he click on set button a dialog box comes and say like you have selected x date and x time or in any way a message should appear on screen like user have selected this time. So i built the code but as my app comes to that activity it always got forcefully stopped.There is no problem with the xml file relating to display the data because when i comment java lines of fetching the values from datePicker and timePicker, app works absolutely fine. Still i am posting both files code for easy to understanding. also posting the log cat exception. I have removed all unnecessary code like import and packages and extra button etc To make it quick readable.

This is the code of .xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="10"
android:id="@+id/commonlayout" android:background="#FFFFFF">

<LinearLayout android:id="@+id/llheader"
    android:layout_width="fill_parent" android:layout_height="20dp"
     android:layout_weight="1"
     android:background="@drawable/bg">

    <RelativeLayout android:id="@+id/relativeLayout1"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:layout_gravity="center"> <!--header-->
        <TextView
            android:id="@+id/txt_header"
            android:layout_width="wrap_content"          
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"/>            
        </RelativeLayout>           
</LinearLayout>
 <ScrollView 
   
Edit
Report

1 Answer

1
ScrollView DTPicker = (ScrollView) View.inflate(TimeDate.this,R.layout.time_date, null);
Button  btnSet = (Button) DTPicker.findViewById(R.id.btnSetDateTime);
final   DatePicker dp = (DatePicker) DTPicker.findViewById(R.id.datePicker);
final   TimePicker tp = (TimePicker) DTPicker.findViewById(R.id.timePicker);

replace the above line with below

ScrollView DTPicker = (ScrollView)findViewById(R.id.scrollView1);
Button  btnSet = (Button)findViewById(R.id.btnSetDateTime);
final   DatePicker dp = (DatePicker)findViewById(R.id.datePicker);
final   TimePicker tp = (TimePicker)findViewById(R.id.timePicker);
answered 2012-04-27T07:59:02.203

Your Answer