Hi friends today i am going to show you how to deal with android using java.
First you have to do these steps…………
1.Download the Android SDK.(Download)
2.Install the ADT plugin for Eclipse (if you’ll use the Eclipse IDE).
3.Download the latest SDK tools and platforms using the SDK Manager.
Here i’m using Eclipse IDE.
As a first step here I’hv created simple application.
This is my Virtual android device
In here when user add text to text field and………..
Adding Text
then press “Click” button it will show like this…………
Output
Here i design interface using XML file res/layout/main.xml (path of XML file)
Here is the code…..
main.xml >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.00"
android:text="@string/hello" />
<EditText
android:id="@+id/edit_message"
android:layout_width="279dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="@string/button_send" />
</LinearLayout>
In this code EditText means the the text field ,
TextView means the text lable and I hv use Linear Layout to place component in the screen.
When user click button the text in the the text field should be change there for i have wrote method called “onClick”
in my Main java file.
You can find your main java file in src/yourname.java.
Name of my java file is TestActivity,java
TestActivity.java >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
package test.madushanka;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) { //this is the metohd to constructing interface
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick(View view){ // onClick method
EditText e=(EditText) findViewById(R.id.edit_message); // access text field using id of my main.xml
String s=e.getText().toString(); //getting the text in the text field as a String
e.setText("Welcome "+s+"!!!"); //set text of text field
}
}
you can download this apk file here (Download)
Android is easy to learn if you know java well.
Try it your self just like me.