Contributed by: Amit Kumar Saha
Before you can get started with developing Android applications, you are advised to acquaint yourself with:
Please refer to the Android SDK documentation for information on the above.
You will need:
The Undroid Project provides the plugins for Android development on NetBeans. The plugins are available for download from here.
After you have installed the plugins,you have to add your Android platform by going to Tools->Java Platforms:
Point it to your Android SDK location:
Now, go to File->New Projects. You should now see a new entry for Android:
Go ahead with the default application name (or change it!)
You should see a new project structure as below:
The file MainActivity.java is as shown below:
package org.me.androidapplication1;
import android.app.Activity;
import android.os.Bundle;
/**
*
* @author amit
*/
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// ToDo add your GUI initialization code here
}
}
As described in the Android SDK documentation, an Android application is organized as a set of activities. The file MainActivity.java that has been generated is the main activity class for this application.
Where is our Hello World?
Just add
setContentView(R.layout.main);
to the above file in place of
// ToDo add your GUI initialization code here
This should have been generated by the plugin, because the main.xml containing the main view was generated.
Alternatively we can do the following.
We shall now add support to the skeleton code to display the text- Hello, Android. Add the following to the above file in place of the "// ToDo add your GUI initialization code here":
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
You will notice that the IDE complains- "Cannot find symbol". This is because we need to import the class TextView. Its easy with NetBeans. Just click on the yellow bulb and select "Add import for.."
The file should now look like:
package org.me.androidapplication1;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
/**
*
* @author amit
*/
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
Now, run the project again
If you have installed the Android examples plugin, you may also try the sample projects. Go to File->New Project->Samples->Android:
So, this was the first look at Android development using NetBeans. For those who were complaining of the absence of a NetBeans plugin for Android development, its time to get started and get some creative juice flowing.
Make sure you check out the references for more information on Android.
As of March 10, 2008 the Undroid plugins do not work correctly with Android SDK release m5-rc14. For a workaround please refer this blog post at http://abhrajit.blogspot.com/2008/03/undroid-and-android-sdk-m5-rc15.html Thanks Abhrajit!
| add-android-platform-1.png | ![]() |
19023 bytes |
| add-android-platform.png | ![]() |
59010 bytes |
| add-new-class.png | ![]() |
17971 bytes |
| install-plugin.png | ![]() |
48739 bytes |
| new-project-1.png | ![]() |
69266 bytes |
| new-project.png | ![]() |
59109 bytes |
| project-structure.png | ![]() |
11801 bytes |
| run-default.png | ![]() |
127973 bytes |
| run.png | ![]() |
30957 bytes |
| samples.png | ![]() |
46928 bytes |