.:: Welcome To My Personal Blog ::.

Saturday, February 25, 2012

Begin Android Programming with Netbeans (Part - 2 of 2)

The full process is tested on the computer with following configuration:

Processor: Core i3 2.53 GHz
RAM: 2.00 GB
OS: 32-bit Windows 7
IDE: Netbeans 6.9.1

Here is the step-by-step process to begin android programming with netbeans. Hope it will be helpfull for all. (Part 2)

Link to Part 1 of 2

Step 5: Writing First Program

Now it's time to create the first android program using netbeans.

Open Netbeans and goto File>>New Project. Select Android>>Android Project and then click next.
Provide a project name and a package name with three parts (example: part1.part2.part3). Give an activity name which will be shown in the application list of your android device. Select the target name you want and click finish.
In the main file under source package, you will find the following code:


package part1.part2.part3;

import android.app.Activity;
import android.os.Bundle;

public class MainActivity_name extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

There can be an error showing on line 13. Don't do anything to remove it. Just Clean and Build will blow it away.

Add the import after line 4: import android.widget.TextView;

Add the following lines after line 13:
        TextView text1 = new TextView(this);
   text1.setText("Hello World");
   setContentView(text1);
       
Then the full code will be the following:

package part1.part2.part3;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity_name extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView text1 = new TextView(this);
        text1.setText("Hello World");
        setContentView(text1);
    }
}

Now Build and Run the project.

An emulator window will open an OS will be loaded within a few minutes.
(Do not close the emulator)

Step 6: Adding the Developed Application (Installing .apk file)

To add the application to your virtual device application list, do the following:

Open command prompt. (Goto Run, type cmd and press enter) Move to the platform-tools directory under Android SDK directory where you installed Android SDK Tool by using cd command. Here you will find a file named adb.exe that will be used to install the .apk file in the virtual device. Type adb.exe<space>install<space><path to your .apk file> in the command prompt and press enter.
You can find the .apk file of your developed application under bin directory of your main project directory.

Step 7: View your own Android Application

Now on the emulator window, you can find your application in the application list by pressing the menu button on Virtual Android Device.





1 comment:

  1. good news......visit us to read more...https://www.daily-bangladesh.com/information-technology/208531

    ReplyDelete

Popular Posts