Wednesday, 12 September 2012

Adapters and types of Adapters used in Android.....

Adapters and types of Adapters used in Android.....


An Adapter object acts as a bridge between an AdapterView and the underlying data for that view. The Adapter provides access to the data items. The Adapter is also responsible for making a View for each item in the data set. 
An AdapterView is a view whose children are determined by an Adapter.
Some examples of AdapterViews are ListView, GridView, Spinner and Gallery.

There are several types or sub-classes of Adapter:
  • ListAdapter: Extended Adapter that is the bridge between a ListView and the data that backs the list. Frequently that data comes from a Cursor, but that is not required. The ListView can display any data provided that it is wrapped in a ListAdapter.
  • ArrayAdapter: A ListAdapter that manages a ListView backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView.
  • CursorAdapter: Adapter that exposes data from a Cursor to a ListView widget. The Cursor must include a column named "_id" or this class will not work.
  • HeaderViewListAdapter: ListAdapter used when a ListView has header views. This ListAdapter wraps another one and also keeps track of the header views and their associated data objects.This is intended as a base class; you will probably not need to use this class directly in your own code.
  • ResourceCursorAdapter: An easy adapter that creates views defined in an XML file. You can specify the XML file that defines the appearance of the views.
  • SimpleAdapter: An easy adapter to map static data to views defined in an XML file. You can specify the data backing the list as an ArrayList of Maps. Each entry in the ArrayList corresponds to one row in the list.
  • SimpleCursorAdapter: An easy adapter to map columns from a cursor to TextViews or ImageViews defined in an XML file. You can specify which columns you want, which views you want to display the columns, and the XML file that defines the appearance of these views.
  • SpinnerAdapter: Extended Adapter that is the bridge between a Spinner and its data. A spinner adapter allows to define two different views: one that shows the data in the spinner itself and one that shows the data in the drop down list when the spinner is pressed.
  • WrapperListAdapter: List adapter that wraps another list adapter. The wrapped adapter can be retrieved by calling getWrappedAdapter().

How to copy one bean properties to other in Java...

How to copy one bean properties to other in Java...

1)How to copy one Bean properties to other in JAVA:

As we know the Bean class containing the variables with setters and getters methods. We can access through the getXxx and setXxx methods by different properties. To copy the properties form one bean to another they should have same datatypes.

To Run our program the requirements are:
• commons-beanutils , you can download from here http://commons.apache.org/beanutils/
• commons-loging , you can download from here http://commons.apache.org/logging/
• Eclipse
• JDK 1.6

1)Person.java

package com.sunil;

public class Person {

private String name;
private int age;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}

2)CopyPerson.java

package com.sunil;

public class CopyPerson {

private String name;
private int age;

public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

}

The TestCopyProperties class will let us test copying properties from one bean to another. First, it creates a person object(fromBean) and a copyPerson(toBean) object. It outputs these objects to the console. Then, it call the BeanUtils.copyProperties() method with toBean as the first parameter and fromBean as the second parameter. Notice that the object that is copied to is the first parameter and the object that is copied from is the second parameter.

In the below program we are copying the properties from person object to copyPerson object using BeanUtils.copyProperties(targer,source) method.

3)TestCopyProperties.java

package com.sunil;

import org.apache.commons.beanutils.BeanUtils;

public class TestCopyProperties {

public static void main(String[] args) throws Exception{

Person person = new Person();
person.setName("Ramu");
person.setAge(24);

CopyPerson copyPerson = new CopyPerson();
copyPerson.setName("Krishna");
copyPerson.setAge(22);

System.out.println("----Before copying the properties----");
System.out.println("--Person Proerpties--");
System.out.println(person.getName());
System.out.println(person.getAge());
System.out.println("--copyPerson Properpties--");
System.out.println(copyPerson.getName());
System.out.println(copyPerson.getAge());

//BeanUtils.copyProperties(destination,source);
BeanUtils.copyProperties(copyPerson,person);

System.out.println("----After Copying the properties from bean one to two----");
//the Person bean properties copied to CopyProperties bean
System.out.println(copyPerson.getName());
System.out.println(copyPerson.getAge());
}
}

0/P:

----Before copying the properties----
--Person Proerpties--

Ramu
24

--copyPerson Properpties--

Krish
26

----After Copying the properties from bean one to two----

Ramu
24

Tuesday, 11 September 2012

Eclipse Shorcuts

Eclipse Shortcuts:

Eclipse shortcut keys helps in developing your project faster n saves ur time.

You can download Eclipse shortcuts keys table pdf file from here.
Download
You can also download Netbeans shortcuts keys table pdf file from here.
Download
 
a)General editing:
  • F12 – Focus on current editor.
  • CTRL+ L – Go to line number.
  • CTRL+ D – Delete a line.
  • CTRL +<- or -> – Move one element left or right.
  • CTRL+ M – Maximize editor.
  • CTRL+ SHIFT+ P – Go to the matching parenthesis.
b)To Edit Java:


Shortcut Description
Ctrl + 1 Quickfix; result depending on cursor position
Ctrl + Space Content assist/ code completion
Ctrl + T Show the inheritance tree of the current Java class
Ctrl + O Show all methods of the current class, press Ctrl + O again to show the inherited methods.
F12 Focuses on the editor (especially helpful if you work with Fast Views).
Ctrl + M Maximize Java editor
Ctrl + Shift + F Format source code
Ctrl + Shift + O Organize the imports; will import the missing import statements.
Ctrl + Q Go to position the cursor at the last changed position in the editor.
  • CTRL +SHIFT+ U – Find reference in file.
  • CTRL / – Comment a line.
  • F3 – Go to the declaration of the variable.
  • F4 – Show type hierarchy of on a class.
  • CTRL +T – Show inheritance tree of current token
  • SHIFT+ F2 – Show Javadoc for current element.
  • ALT+ SHIFT +Z – Enclose block in try-catch.
c) For file navigation:

Ctrl + Shift + R Open / Search for resources, e.g. files
Ctrl + Shift + T Open / Search for Types
Ctrl + E Allows to select an editor from the currently open editors
Ctrl + F8 Shortcut for switching perspectives
Alt + ← or Alt + → Go to previous/ next editor position in history
Ctrl-PageUp/PageDown Switch to previous/next editor
F3 Go to the declaration of this variable
Ctrl + Shift + P Go to the matching bracket
 ALT +<- or ALT+ -> – Go to previous or next edit positions from editor history list.

d)To Debug,Run & search:


Ctrl + . Go to the next problem / error
Ctrl + , Go to the previous problem / error
F4 on a variable Show type hierarchy
Ctrl + J , Ctrl + K Incremental search, find next
Ctrl + Shift + G Search for references in the workspace

  • CTRL +. or , – Navigate to next or previous error.
  • F5 – Step into.
  • F6 – Step over.
  • F8 – Resume
  • CTRL+ Q – Inspect.
  • CTRL+ F11 – Run last run program.
  • CTRL+ 1 – Quick fix code.
  • CTRL+ H – Java search in workspace.
  •  Alt + Shift + X - J-Run current selected class as Java application
e)For Deleting:

Shortcut Description
Ctrl + D Deletes line
Ctrl + Shift + DEL Delete until end of line
Ctrl + DEL Delete next element
Ctrl + BACKSPACE Delete previous element

f) Others:
  • Ctrl + 2, L-Assign statement to new local variable.
  •  Ctrl + 2, F-Assign statement to new field.
  •  Shift + F2-Show the Javadoc for the selected type / class / method.
  •  Alt+Shift + N + Letter-Type shortcut for the command, e.g. njc to create a new Java class or npip to create a new Plugin project.
  •  Alt + Shift + Z-Surround block with try and catch.
  •  Alt + Shift + R-Rename.
  •  Ctrl+2, R-Rename locally (in file), faster then Alt + Shift + R.
  •  Alt + Shift + T-Opens the quick refactoring menu.
 

Android Installation procedure

 


Android Installation:

Hi everyone,Android installation is easier if u follow the below steps.I have tried to explain it in brief so it may be helpul for someone.


Software Requirement:

1)Jdk & Jre(above 5.0 ).
2)Eclipse(latest one).
3)Android sdk.
4)Android plugin to eclipse.

Before  installing Android your Java developement environment should be ready.

1)Steps to Instal Java Developement environment :

2)Give the jdk and jre path in advanced settings to run java program. 
 i.e.
a) go to control pane->click Advanced system settings->select Environment variable in pop up->click new and create varialble with variable name JAVA_HOME and for variable path give ur jdk path in c as C:\Program Files\Java\jdk1.6.0_24\bin.
 
b)Same way click new and Jre also with name JRE_Home and path as  C:\Program Files\Java\jre6\bin.                                     

c)Later edit path in system variable and add ur jdk path.
 i.e D:\oracle\product\10.2.0\db_1\bin;C:\Program Files\Java\jdk1.6.0_24\bin,C:\Program Files\Java\jre6\bin 

d)Now u can download Eclipse and run ur java program.

2)Steps to Instal Android Developement environment :

 1)Download Android SDK
        download Android SDK from http://developer.android.com/sdk/index.html
      
        2)Installing the SDK :
On Windows, right-click on My Computer and select Properties. Under the Advanced tab, hit the Environment Variables button, and in the dialog that comes up, double-click on Path (under System Variables). Add the full path to the tools/directory to the path.

     3)Download Eclipse: Download Eclipse from http://www.eclipse.org/downloads/

     4)Download ADT Plug-in
  •  Start Eclipse, then select Help > Install New Software.   
  •  In the Available Software dialog  click Add.   
  •   In the Add Site dialog that appears, enter a name for the remote site in the "Name" field.                     E.g. AndroidPlug-in  
  • In the "Location" field, enter this URL: https://dl-ssl.google.com/android/eclipse/  .                     Then  Click OK.                                                                
  • Go  Back to the Available Software view, you should now see "Developer Tools" added to the list. Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development.Click NEXT.              
  • In the resulting Install Details dialog, the Android DDMS and Android Development Tools features are listed. Click Next to read and accept the license agreement and install any dependencies, then click Finish.
  • Restart Eclipse. 
 5) Configuring ADT plug-in eclipse:
  • Select Window > Preferences... to open the Preferences panel
  • Select Android from the left panel.
  • For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory.
  • ·Click Apply, and then OK. 






      
     6)Create AVD:

Click on Android SDK and AVD Manager icon or Window > Android SDK and AVD Manager


7  
    7)Running Application: 
  • Import the source code to eclipse.
  • Import required JAR files on project properties > Java build path > Libraries. 
  • Now run the application.