Saturday, 31 August 2013

Button

Open Eclipse IDE.

Click File>New>Android Application Project.

Fill the Application Name "AndroidButton"
Fill the Project Name "AndroidButton"
The package name is of type "com.codingredefined.androidbutton"
Then click next.

Then Configure Project window opens. Keep the default settings and click next.

Now you can choose the icon for your app from the provided icons or can choose a file from your system.
Again click next.

Now give your activity(ie the fie in which all the logic is to be performed) a name "MainActivity", then the layout name "activity_main" and click Finish.


Open the layout folder in the res folder.
Add the following code to activity_main.xml:
<TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World" />

    <Button
        android:id="@+id/b"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tv"
        android:text="Click Me" />
The above code will make the button appear on screen.

Now to make the Button working
Open MainActivity.java and write:

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity
{

TextView tv;
Button b;

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

tv=(TextView)findViewById(R.id.tv);
b=(Button)findViewById(R.id.b);

b.setOnClickListener(new View.OnClickListener()
{

@Override
public void onClick(View v)
{
// TODO Auto-generated method stub

tv.setText("Button Clicked...!");

}
});

}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

Now save both the layout and activity file.
Now in the Package Explorer right click your app name
Click Run As>Android Application.

Your application should look like this:



Video Tutorial


Thursday, 29 August 2013

My First App


Lets start developing Android Apps.
Open Eclipse IDE.

Click File>New>Android Application Project.
Fill the Application Name, whatever name you want to give to your application.
Fill the Project Name and then the package name.
The package name is of type com.companyname.appname.
Then click next.

Then Configure Project window opens. Keep the default settings and click NEXT.


Now you can choose the icon for your app from the provided icons or can choose a file from your system.
Again click next.

Now give your activity(ie the fie in which all the logic is to be performed) a name, then the layout name and click Finish.


Now in the Package Explorer right click your app name
Click Run As>Android Application.
After doing this, wait for the emulator to start. Your application will be automatically launched after the emulator gets ready.

To know how the "Hello World" is printed go to activity_main.xml and check the TextView.


Remember emulator takes some time to get ready but after its ready you can test your further applications on the same emulator so do not close the emulator till you are working.
The application being shown on the emulator is having the default settings which we will manipulate in next posts.

Wednesday, 28 August 2013

Before Starting Android

Before we start developing Android apps, there is something you must know.
When we create new project, of all the system generated files a few are of utmost importance as whole of the android programming is done on these files.
The Files are:

  • main.java
    • In this file, we perform the coding and apply the logics of our program.
  • layout.xml
    • In this file, we create the UI or we can say how the application will look to the user.
  • menu.xml
    • In this file, we create the menu items for any page or we can use the same menu items for the whole application.
  • manifest.xml
    • This file contains the information of all the classes created either by us or by the IDE. This file also contains the permissions required by our application(if any).

Installing Android SDK



There are 10 easy steps to install Android SDK(Software Development Kit) on your computer and start coding.

    1. Download the Android adt bundle free of cost from http://developer.android.com/sdk/index.html. There is also a link to install the SDK for platforms other than Windows.
    After downloading extract the folder to your desired location.


    To begin coding in Android latest JDK (www.oracle.com/technetwork/java/javase/downloads/index.html) must be pre installed on the system.

    Then open Eclipse. It is the IDE for Android.


    Set the location to store all the projects or applications you create termed as Workspace.
    Then in the Menu Bar open Windows and then Android SDK Manager and download all the components under API level 17 ie 4.2 Jelly Bean and Extras.



    Then open Android Virtual Device Manger.

    This allows to create a emulator where you would test the applications you create before testing on the real devices.


     Save the emulator with the following preferences:
      • Name : <anything of your choice>
      • Device : 4" WVGA 
      • Target : Android 4.2.2 API 17
      • CPU : ARM
      • SD Card Size : 100MB
      • Keep the default settings for the rest of fields. 
      • Click OK.

    Now your IDE is ready to build Android Apps.

    Introduction to ANDROID

    Android is an Linux based Operating System devised primarily for touch screen smartphones and tablets by Google. Founded in Palo Alto, California in October 2003 by Andy Rubin, Rich Miner, Nick Sears and Chris White. All the version of Android are named on some eatables.
    Earlier versions released:
    1.5 Cupcake(April 2009)
    1.6 Donut(September 2009)
    2    Eclair(October 2009)
    2.2 Froyo(May 2010)
    2.3 Gingerbread(December 2010)
    3    Honeycomb(May 2011)
    4    IceCream Sandwich(December 2011)
    4.1 Jelly Bean(July 2012)
    4.2 Jelly Bean(November 2012)
    4.3 Jelly Bean (July 2013)
    4.4 KitKat (October 2013). This is the latest android in use today.

    WelCome to the World of Programming

    Get yourself sound in recently trending mobile programming language ANDROID.
    Start from the scratch and develop a full fledged application.