Monday 13 May 2013

Date Picker Example

1) create a file named DatePick.java
=======================
package com.mrs.aspi_motors;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;

public class DatePick extends Activity implements OnClickListener{
    private EditText edtDate = null;
    private ImageView imgDatePicker;
    private Button btnBack = null;
    //private EditText edtOwner_Name = null;
    private EditText edtEmail_ID = null;
    private EditText edtMobile_No = null;
    private EditText edtComments = null;
    private Spinner spnBrand = null;
    private Spinner spnProduct = null;
    private Spinner spnCarModel = null;
    private Spinner spnServiceType = null;
    private Spinner spnChasisNo = null;
    private Button btnSubmit = null;
    private int intBrandID = 0, intProductID = 0,intModelID = 0;
    private SharedPreferences mSharedPreferencesRead=null;
    private CommanClass mCommanClass = null;
    private String strName = null,strMobile_No = null,strEmail_id = null;
    private String strUserId = null;
    private String strMessage = null;
    private String strFailMessage = null;
    private String strOwnerName = null;
    private String strEmailID=null;
    private String strMobileNo=null;
    private int Year=0,Month=0,Day=0;
   
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.xservice_request);
       
        mSharedPreferencesRead = getSharedPreferences(Constant.SHAREDPREFERENCES.SHAREDPREFERENCE, MODE_WORLD_READABLE);
        mCommanClass = new CommanClass();

            strUserId = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_USER_ID, "");
            strOwnerName = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_NAME_OF_OWNER, "");
            strEmailID = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_EMAIL_ID, "");
            strMobileNo = mSharedPreferencesRead.getString(Constant.LOGIN_SHAREPREFERENCE.LS_MOBILE_NO, "");
        InItSpinnerData();
        btnBack = (Button)findViewById(R.id.btnBack);
        btnBack.setOnClickListener(this);
        btnSubmit = (Button)findViewById(R.id.btnSubmit);
        btnSubmit.setOnClickListener(this);
//        edtOwner_Name = (EditText)findViewById(R.id.edtOwnerName);
//        edtOwner_Name.setText(strOwnerName);
        edtEmail_ID = (EditText)findViewById(R.id.edtEmail_ID);
        edtEmail_ID.setText(strEmailID);
        edtMobile_No = (EditText)findViewById(R.id.edtMobileNo);
        edtMobile_No.setText(strMobileNo);
        edtComments = (EditText)findViewById(R.id.edtComments);
        // capture our View elements
        edtDate = (EditText) findViewById(R.id.edtDate);
       
        imgDatePicker = (ImageView) findViewById(R.id.img_calender);

        // add a click listener to the button
        imgDatePicker.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                //showDialog(DATE_DIALOG_ID);
                DateDialog();
            }
        });
       
      final Calendar c = Calendar.getInstance();
      Year = c.get(Calendar.YEAR);
      Month = c.get(Calendar.MONTH);
      Day = c.get(Calendar.DAY_OF_MONTH);
      updateDisplay();
//      Date mDate = new Date();
//        mDate.setYear(Year-1900);
//        mDate.setMonth(Month);
//        mDate.setDate(Day);
//   
//     String selectedDate =(String)DateFormat.format("yyyy-MM-dd",mDate).toString();
//     edtDate.setText(selectedDate);

//        // get the current date
//        final Calendar c = Calendar.getInstance();
//        mYear = c.get(Calendar.YEAR);
//        mMonth = c.get(Calendar.MONTH);
//        mDay = c.get(Calendar.DAY_OF_MONTH);
//
//        // display the current date (this method is below)
//        updateDisplay();
        //new Service_Request().execute("");
    }
    //***********************************************************************************************************************
    /**
     * @author Manisha
     * @param none
     * @return void
     * @use This function is used for getServiceType
     */
   
      private ArrayList<Integer> alstServiceType_Id=null;
      private ArrayAdapter<String> aadpServiceTypeName=null;     
      private void GET_SERVICETYPE() {     
          alstServiceType_Id=new ArrayList<Integer>();
          alstServiceType_Id.clear();
          aadpServiceTypeName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
          aadpServiceTypeName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          aadpServiceTypeName.clear();
          spnServiceType.setAdapter(aadpServiceTypeName);
          DBConstant.OpenDatabase(ServiceSetupRequest.this);       
               Cursor c = DBConstant.mDBHelper.GET_SERVICE_TYPE(DBConstant.mSQLiteDatabase);               
                if(c!=null){
                    if(c.getCount() > 0){
                        c.moveToFirst();
                        while(c.isAfterLast()==false){
                            alstServiceType_Id.add(c.getInt(1));
                            aadpServiceTypeName.add(c.getString(2).toString());           
                            c.moveToNext();
                        }
                        spnServiceType.setAdapter(aadpServiceTypeName);
                    }
                }
                c.close();
          DBConstant.CloseDataBase();
        }
     
    //***********************************************************************************************************************
    /**
     * @author Manisha
     * @param none
     * @return void
     * @use This function is used for getBrandData
     */
   
      private ArrayList<Integer> alstBrandID=null;
      private ArrayAdapter<String> aadpBrandName=null;     
      private void GET_SELECTED_BRAND() {     
          alstBrandID=new ArrayList<Integer>();
          alstBrandID.clear();
          aadpBrandName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
          aadpBrandName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          aadpBrandName.clear();
          alstBrandID.add(Constant.SPPINER_CONSTANT.SERVICE_SETUP_DEFAULT_ID);
          aadpBrandName.add(Constant.SPPINER_CONSTANT.SELECT_BRNAD);
          spnBrand.setAdapter(aadpBrandName);
          DBConstant.OpenDatabase(ServiceSetupRequest.this);       
               Cursor c = DBConstant.mDBHelper.GET_SELECTED_BRNAD_NAME(DBConstant.mSQLiteDatabase);               
                if(c!=null){
                    if(c.getCount() > 0){
                        c.moveToFirst();
                        while(c.isAfterLast()==false){
                            alstBrandID.add(c.getInt(0));
                            aadpBrandName.add(c.getString(1).toString());           
                            c.moveToNext();
                        }
                        spnBrand.setAdapter(aadpBrandName);
                    }
                }
                c.close();
          DBConstant.CloseDataBase();
        }
     
    //***********************************************************************************************************************
        /**
         * @author Manisha
         * @param none
         * @return void
         * @use This function is used for getProductData
         */
          private ArrayList<Integer> alstProductID=null;
          private ArrayAdapter<String> aadpProductName=null;     
          private void GET_SELECTED_PRODUCT(int pos){     
              alstProductID=new ArrayList<Integer>();
              alstProductID.clear();
              aadpProductName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
              aadpProductName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              aadpProductName.clear();
              alstProductID.add(Constant.SPPINER_CONSTANT.SERVICE_SETUP_DEFAULT_ID);
              aadpProductName.add(Constant.SPPINER_CONSTANT.SELECT_PRODUCT);
              spnProduct.setAdapter(aadpProductName);
              DBConstant.OpenDatabase(ServiceSetupRequest.this);       
                   Cursor c = DBConstant.mDBHelper.GET_SELECTED_PRODUCT_NAME(DBConstant.mSQLiteDatabase,alstBrandID.get(pos));               
                    if(c!=null){
                        if(c.getCount() > 0){
                            c.moveToFirst();
                            while(c.isAfterLast()==false){
                                alstProductID.add(c.getInt(0));
                                aadpProductName.add(c.getString(1).toString());                                   
                                c.moveToNext();
                            }
                            spnProduct.setAdapter(aadpProductName);
                        }
                    }
                    c.close();
              DBConstant.CloseDataBase();
          }
         
    //***********************************************************************************************************************
        /**
         * @author Manisha
         * @param none
         * @return void
         * @use This function is used for getModelData
         */
          private ArrayList<Integer> alstModelID=null;
          private ArrayAdapter<String> aadpModeName=null;     
          private void GET_SELECTED_MODEL(int pos){     
              alstModelID=new ArrayList<Integer>();
              alstModelID.clear();
              aadpModeName = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
              aadpModeName.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              aadpModeName.clear();
              alstModelID.add(Constant.SPPINER_CONSTANT.SERVICE_SETUP_DEFAULT_ID);
              aadpModeName.add(Constant.SPPINER_CONSTANT.SELECT_MODEL);
              spnCarModel.setAdapter(aadpModeName);
              DBConstant.OpenDatabase(ServiceSetupRequest.this);       
                   Cursor c = DBConstant.mDBHelper.GET_SELECTED_MODEL_NAME(DBConstant.mSQLiteDatabase,alstProductID.get(pos));               
                    if(c!=null){
                        if(c.getCount() > 0){
                            c.moveToFirst();
                            while(c.isAfterLast()==false){
                                alstModelID.add(c.getInt(0));
                                aadpModeName.add(c.getString(1).toString());                                   
                                c.moveToNext();
                            }
                            spnCarModel.setAdapter(aadpModeName);
                        }
                    }
                    c.close();
              DBConstant.CloseDataBase();
          }
         
    //***********************************************************************************************************************
        /**
         * @author Manisha
         * @param none
         * @return void
         * @use This function is used for getModelData
         */
        //  private ArrayList<Integer> alstModelID=null;
          private ArrayAdapter<String> aadpChassis_number=null;     
          private void GET_SELECTED_CHASSIS_NUMBER(int pos){     
            // alstModelID=new ArrayList<Integer>();
            //  alstModelID.clear();
              aadpChassis_number = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
              aadpChassis_number.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
              aadpChassis_number.clear();
              aadpChassis_number.add(Constant.SPPINER_CONSTANT.SELECT_CHASSIS_NUMBER);
              spnChasisNo.setAdapter(aadpChassis_number);
              DBConstant.OpenDatabase(ServiceSetupRequest.this);       
                   Cursor c = DBConstant.mDBHelper.GET_SELECTED_CHASSIS_NUMBER(DBConstant.mSQLiteDatabase,intModelID);               
                    if(c!=null){
                        if(c.getCount() > 0){
                            c.moveToFirst();
                            while(c.isAfterLast()==false){
                                //alstModelID.add(c.getInt(0));
                                aadpChassis_number.add(c.getString(0).toString());                                   
                                c.moveToNext();
                            }
                            spnChasisNo.setAdapter(aadpChassis_number);
                        }
                    }
                    c.close();
              DBConstant.CloseDataBase();
          } 
         
          public void InItSpinnerData(){
              spnBrand = (Spinner)findViewById(R.id.spnBrand);
              spnProduct = (Spinner)findViewById(R.id.spnProduct);
              spnCarModel = (Spinner)findViewById(R.id.spnModel);
              spnChasisNo = (Spinner)findViewById(R.id.spnChasisNumber);
              spnServiceType = (Spinner)findViewById(R.id.spnServiceType);
              GET_SERVICETYPE();
              GET_SELECTED_BRAND();
             
              spnBrand.setOnItemSelectedListener(new OnItemSelectedListener() {
                    @Override
                    public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
                        intBrandID = alstBrandID.get(arg2);
                        //System.out.println("intBrandID=="+intBrandID);
                        GET_SELECTED_PRODUCT(arg2);
                    }
                    @Override
                    public void onNothingSelected(AdapterView<?> arg0) {
                       
                    }
             });
             spnProduct.setOnItemSelectedListener(new OnItemSelectedListener() {
                    @Override
                    public void onItemSelected(AdapterView<?> arg0, View arg1,
                            int arg2, long arg3) {
                        intProductID = alstProductID.get(arg2);
                        GET_SELECTED_MODEL(arg2);
                    }
                    @Override
                    public void onNothingSelected(AdapterView<?> arg0) {
                       
                    }
             });
           
             spnCarModel.setOnItemSelectedListener(new OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
                    intModelID = alstModelID.get(arg2);
                    GET_SELECTED_CHASSIS_NUMBER(arg2);
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                   
                }
            });
//             spnChasisNo.setOnItemSelectedListener(new OnItemSelectedListener() {
//
//                    @Override
//                    public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
//                        intModelID = aadpChassis_number.g
//                    }
//
//                    @Override
//                    public void onNothingSelected(AdapterView<?> arg0) {
//                       
//                    }
//                });
          }
         
   
    private ProcessDialog mProcessDialogLogin=null;
    private class Service_Request extends AsyncTask<String, String, String>
    {        
            protected void onPreExecute(){
                mProcessDialogLogin = new ProcessDialog(ServiceSetupRequest.this,Constant.PROGRESSBAR.SERVER,Constant.PROGRESSBAR.LOADING);
                    super.onPreExecute();
            }       
            protected String doInBackground(String... params){
                      String strURL = getResources().getString(R.string.SERVICE_REQUEST_URL);                     
                      ArrayList<NameValuePair> mNameValuePair = new ArrayList<NameValuePair>();
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.USER_ID, strUserId.toString().trim()));
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.BRAND,String.valueOf(intBrandID)));
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.PRODUCT, String.valueOf(intProductID)));
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.MODEL, String.valueOf(intModelID)));
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.DATE, edtDate.toString().trim()));
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.CHASIS_NUMBER, spnChasisNo.getSelectedItem().toString().trim()));
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.MOBILE_NO, edtMobile_No.getText().toString().trim()));
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.SERVICE_TYPE,spnServiceType.getSelectedItem().toString().trim()));
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.EMAIL_ID, edtEmail_ID.getText().toString().trim()));
                      mNameValuePair.add(new BasicNameValuePair(Constant.SERVICE_REQUEST_REQUEST.COMMENTS, edtComments.getText().toString().trim()));

                      System.out.println("mNameValuePair=="+mNameValuePair.toString());
                      return mCommanClass.PostConnection(strURL, mNameValuePair); 
            }
           
            protected void onPostExecute(String result) {
            super.onPostExecute(result);
            mProcessDialogLogin.dismiss();
                if(result!=null)
             {
                    try {
                           //System.out.println("SERVICE_SETUP_REQUEST ==="+result.toString());
                             JSONObject mJSONOBJECT = new JSONObject(result);
                            String strType = mJSONOBJECT.getString(Constant.JSON.TYPE);
                             if(strType.toString().trim().equalsIgnoreCase(Constant.JSON.OK)){
                                 strMessage = mJSONOBJECT.getString(Constant.JSON.MESSAGE);
                                 ServiceRequstDialog();
                             }
                             else{
                                 strFailMessage = mJSONOBJECT.getString(Constant.JSON.MESSAGE);
                                 ServiceRequstFailDialog();
                             }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }                                                 
             }       
                else{
                    Toast.makeText(ServiceSetupRequest.this, Constant.SERVERCONNERROR,Toast.LENGTH_SHORT).show();
             }
           }
  }
   


    @Override
    public void onClick(View v) {
        if(v==btnBack){
            finish();
        }
        else if(v==btnSubmit){
            if(!BlankSpinner()){
                if(mCommanClass.CheckNetwork(this)){
                    new Service_Request().execute("");
                }
            }
        }
    }
   
    //***********************************************************************************************************************
    /**
     * @author Manisha
     * @param none
     * @return void
     * @use This Dialog is used for show service request dialg
     */ 
    public void ServiceRequstDialog(){
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ServiceSetupRequest.this);
            alertDialogBuilder
                .setMessage(strMessage)
                .setCancelable(false)
                .setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON,new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        finish();
                        dialog.cancel();
                    }
                  });
       
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
    }
    public void ServiceRequstFailDialog(){
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ServiceSetupRequest.this);
            alertDialogBuilder
                .setMessage(strFailMessage)
                .setCancelable(false)
                .setPositiveButton(Constant.COMMON_ALERT.POSITIVE_BUTTON,new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        dialog.cancel();
                    }
                  });
       
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
    }
    private boolean BlankSpinner(){
        boolean boolBlank =  true;
        if(spnServiceType.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_SERVICE_TYPE)){
                Toast.makeText(ServiceSetupRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_SERVICE_TYPE,Toast.LENGTH_SHORT).show();
                boolBlank =  true;
        }else if(spnBrand.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_BRNAD)){
             Toast.makeText(ServiceSetupRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_BRNAD,Toast.LENGTH_SHORT).show();
             boolBlank =  true;
        }
        else if(spnProduct.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_PRODUCT)){
             Toast.makeText(ServiceSetupRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_PRODUCT,Toast.LENGTH_SHORT).show();
             boolBlank =  true;
        }
        else if(spnCarModel.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_MODEL)){
             Toast.makeText(ServiceSetupRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_MODEL,Toast.LENGTH_SHORT).show();
             boolBlank =  true;
        }
        else if(spnChasisNo.getSelectedItem().equals(Constant.SPPINER_CONSTANT.SELECT_CHASSIS_NUMBER)){
             Toast.makeText(ServiceSetupRequest.this,Constant.SPPINER_TOAST_CONSTANT.SELECT_CHASSIS_NUMBER,Toast.LENGTH_SHORT).show();
             boolBlank =  true;
        }
        else{
             boolBlank = false;
        }
        return boolBlank;
    }
    private DatePicker mdatePicker=null;
    private Dialog mDialog=null;
    private View mView=null;
    private void DateDialog(){
        mDialog=new Dialog(this);
        mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mdatePicker=new DatePicker(this);
        mView=LayoutInflater.from(this).inflate(R.layout.xdatelayout, null);
        LinearLayout datedialogview=(LinearLayout)mView.findViewById(R.id.datedialogview);
        datedialogview.addView(mdatePicker);
       
        Button btnok=(Button)mView.findViewById(R.id.btnok);
        btnok.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
//                Toast.makeText(getApplicationContext(), "OK", Toast.LENGTH_SHORT).show();
                DateValidation();
            }
        });

        Button btncancel=(Button)mView.findViewById(R.id.btncancel);
        btncancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //Toast.makeText(getApplicationContext(), "CANCEL", Toast.LENGTH_SHORT).show();
                mDialog.dismiss();
            }
        });
       
        mDialog.setContentView(mView);
        InitDateSet(); 
        mDialog.show();
    }
   
    private void InitDateSet(){
        final Calendar c = Calendar.getInstance();
        Year=c.get(Calendar.YEAR);
        Month=c.get(Calendar.MONTH);
        Day=c.get(Calendar.DAY_OF_MONTH);
        mdatePicker.init(Year,Month ,Day, mDatePickListener);
    }
//     updates the date in the TextView
  private void updateDisplay(){
     
//      edtDate.setText(
//          new StringBuilder()
//                  // Month is 0 based so add 1
//                  .append(mYear).append("-")
//                  .append(mMonth + 1).append("-")
//                  .append(mDay));
       Date mDate = new Date();
       mDate.setYear(Year-1900);
       mDate.setMonth(Month);
       mDate.setDate(Day);
      
       String selectedDate =(String)DateFormat.format("yyyy-MM-dd",mDate).toString();
       edtDate.setText(selectedDate);
  }
    private DatePicker.OnDateChangedListener mDatePickListener =new DatePicker.OnDateChangedListener(){
            @Override
            public void onDateChanged(DatePicker view, int year,int monthOfYear, int dayOfMonth) {
                Year=year;
                Month=monthOfYear;
                Day=dayOfMonth;
               
            }
     };
    
/** 0 if the times of the two Calendars are equal, -1 if the time of this
    Calendar is before the other one, 1 if the time of this Calendar is after the other one.*/
    private int FirstDateCheck(int year,int month,int day){
            final  Calendar CurrentDate = Calendar.getInstance();
             Calendar NewDate = (Calendar) CurrentDate.clone();
            NewDate.set(year, month, day);
            return NewDate.compareTo(CurrentDate);
    }
   
    private void DateValidation(){
        int Result=FirstDateCheck(Year,Month,Day);
        if(Result==0){
            //Toast.makeText(ServiceSetupRequest.this, "equal", Toast.LENGTH_SHORT).show();
            updateDisplay();
            mDialog.dismiss();
        }
        else if(Result ==-1){
            Toast.makeText(ServiceSetupRequest.this, "Please enter valid date", Toast.LENGTH_SHORT).show();
//            CurrentDateSet();
        }
        else if(Result ==1){
            //Toast.makeText(ServiceSetupRequest.this, "after", Toast.LENGTH_SHORT).show();
            updateDisplay();
            mDialog.dismiss();
        }
    }
}


in xml file put
==============
 <LinearLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="0.33">
                    <EditText
                        android:id="@+id/edtDate"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:singleLine="true"
                        android:editable="false"
                        android:textSize="@dimen/inputtext_size"
                        android:padding="@dimen/edit_text_padding"
                        android:background="@drawable/input_bg"/>
                    <ImageButton
                        android:id="@+id/img_calender"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="5dip"
                        android:layout_gravity="right|center_vertical"
                        android:background="@drawable/ic_date"/>
                </LinearLayout>


3) xdatelayout.xml
=============
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="Date Picker"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:textSize="22dip"
     />
    <LinearLayout
    android:id="@+id/datedialogview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    </LinearLayout> 
    <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <Button
        android:id="@+id/btnok"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="OK"
    />
    <Button
        android:id="@+id/btncancel"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Cancel"
    />
    </LinearLayout> 
</LinearLayout>

No comments:

Post a Comment