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).