Wednesday, May 16, 2012

Example 1:

Example 1:

Open 'main.xml' from layout folder.
Then from toolbox add,
And rename the button by right clicking on the button and select 'Edit text..' to 'Done'

For renaming you have to click new string, then fill as like image below.

Then open file from src folder.

then write the code as below.

package com.jeeth.examples.myfirstandroidproject;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MyFirstAndroidProjectActivity extends Activity {
private EditText edittext;
private Button button;

/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

* Initialize EditText and Button
edittext = (EditText) findViewById(;
button = (Button) findViewById(;

* action to perform on button click 
button.setOnClickListener(new View.OnClickListener() {

public void onClick(View arg0) {
edittext.getText(), Toast.LENGTH_LONG).show();


Then run the application, enter text and press button. Then result will be like the image below.