Wednesday, 8 August 2012

How to use Date Picker...

By sukhpal saini

A DatePicker is a widget that allows the user to select a month, day and year.




Create a new Android Application, AndroidDatePicker.

Modify the layout, main.xml, to add a button to start the DatePicker.


<?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"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<Button
    android:id="@+id/datepickerbutton"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="DatePicker"
 />
</LinearLayout>


Modify the main program, AndroidDatePicker.java.

package com.exercise.AndroidDatePicker;

import java.util.Calendar;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.Toast;

public class AndroidDatePicker extends Activity {
 
 private int myYear, myMonth, myDay;
 static final int ID_DATEPICKER = 0;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button datePickerButton = (Button)findViewById(R.id.datepickerbutton);
        datePickerButton.setOnClickListener(datePickerButtonOnClickListener);
    }
    
    private Button.OnClickListener datePickerButtonOnClickListener
     = new Button.OnClickListener(){

   @Override
   public void onClick(View v) {
    // TODO Auto-generated method stub
    final Calendar c = Calendar.getInstance();
    myYear = c.get(Calendar.YEAR);
    myMonth = c.get(Calendar.MONTH);
    myDay = c.get(Calendar.DAY_OF_MONTH);
    showDialog(ID_DATEPICKER);
   }
    };

 @Override
 protected Dialog onCreateDialog(int id) {
  // TODO Auto-generated method stub
  switch(id){
   case ID_DATEPICKER:
    Toast.makeText(AndroidDatePicker.this, 
      "- onCreateDialog -", 
      Toast.LENGTH_LONG).show();
    return new DatePickerDialog(this,
      myDateSetListener,
      myYear, myMonth, myDay);
   default:
    return null;
  }
 }
    
 private DatePickerDialog.OnDateSetListener myDateSetListener
  = new DatePickerDialog.OnDateSetListener(){
   @Override
   public void onDateSet(DatePicker view, int year, 
     int monthOfYear, int dayOfMonth) {
    // TODO Auto-generated method stub
    String date = "Year: " + String.valueOf(year) + "\n"
     + "Month: " + String.valueOf(monthOfYear+1) + "\n"
     + "Day: " + String.valueOf(dayOfMonth);
    Toast.makeText(AndroidDatePicker.this, date, 
      Toast.LENGTH_LONG).show();
   } 
 };
}


A Toast will be displayed in onCreateDialog(), to show that DatePickerDialog() will be created once only (in the first time display the dialog).

How to install .apk file in Emulator (Android 4.0.3 Ver.)

By Sukhpal Saini


download sdk zip file from this link size 471mb

http://www.4shared.com/rar/coomn8TQ/android-sdk-windows.html?refurl=d1url

open above link and click on download now button the sign up for new account or login with existing account.......then download

extract the android-sdk-windows  file in any location of ur hard disk (in my case it is located in D: drive) then follow the images one by one  1 to 8









then

 Copy .APK files:
Now, manually copy and paste the SterilityTestSystem.apk(your .apk file)  to the destination folder "D:\android-sdk-windows\platform-tools\".

wait for start emulator like image 8
Run adb command:
Go to Start>>run>>cmd (open a windows command prompt or shell) and type the following commands "highlighted in bold orange".
cd d:\android-sdk-windows\platform-tools\
comments: we do this in order to change our directory level to where the emulator is installed

adb install Sudoku.apk 
comments: android emulator command to install the SterilityTestSystem application in .apk format.
Thats all, it's done. You must get a success message, Hurray!! You have installed your application successfully.
then check application in apps category of emulator