This article introduces the basics of Android programming to a simple example of an earlier instance program where readers can learn more about the evolution of the Android program to deepen their understanding of Android programming. The biggest difference between a program running platform for Android SDK 1.5 + Eclipse + adt,android and J2ME is that the UI is different, and of course Android is a lot more than J2ME, and J2ME can't be compared. Just started to do Android development, a lot of people are first to write a simple interface, and then add a little control code, this article is this.
The example described in this article is the simple use of LinearLayout + Button + edittext + alertdialog.
The activity is arranged in LinearLayout, with a total of two linearlayout, the first for the full form, the second for the two button, and the second linearlayout under the EditText control.
Here's the code for Main.xml:
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout "xmlns:android=" Schemas.android.com/apk/res/android "android:orientation=" vertical "android:layout_width=" Fill_parent "Android: layout_height= "Fill_parent" > <edittext android:text= "EditText01" android:layout_height= "Wrap_content" Android:layout_width= "Fill_parent" android:id= "@+id/edtinput" ></EditText> <linearlayout android:id= "@ +id/linearlayout01 "android:layout_height=" wrap_content "android:layout_width=" Fill_parent "android:gravity=" Center "> <button android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:text=" show "Android:id=" @+id/btnshow "></Button> <button android:layout_width=" Wrap_content "Android:layout_
height= "Wrap_content" android:text= "clear" android:id= "@+id/btnclear" ></Button> </LinearLayout> </LinearLayout>
Main.xml's UI design for activity is currently designed to be slightly faster than the lwuit on J2ME (similar to Android's GUI design tool), slightly slower than the. NET CF on the WM (. NETCF is Rad).
Next, give the Java code:
Package com.studio.android;
Import android.app.Activity;
Import Android.app.AlertDialog;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.EditText;
The public class Helloandroid extends activity {/** called the ' when ' is the ' The activity ' is a-a-created.
Button btnclear;
EditText Edtinput;
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
btnshow= (Button) Findviewbyid (r.id.btnshow);//control with Code binding btnclear= (Button) Findviewbyid (r.id.btnclear);//Control and code binding edtinput= (EditText) Findviewbyid (r.id.edtinput);//control with code binding Btnshow.setonclicklistener (New Clicklistener ());// Use Click event Btnclear.setonclicklistener (New Clicklistener ());//Use Click event} class Clicklistener implements Onclicklisten er {public void OnClick (View v) {if (v==btnshow) {New Alertdialog.builder (Helloandroid.this). SetIcon (Android.
R.drawable.ic_dialog_alert). Settitle ("Information"). Setmessage (Edtinput.gettext ()). Show ();
else if (v==btnclear) {edtinput.settext ("helloandroid");
}
}
}
}
Just beginning Android development, interface design is the bottleneck of J2ME programmers, but later Android development tools will become more and more intelligent, expect NetBeans to launch a better ADT (NetBeans currently has the Android plug-in). I hope that the example described in this article will help you learn about Android.