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 MyFirstAndroidProjectActivity.java file from src folder.

then write the code as below.

package com.jeeth.examples.myfirstandroidproject;

import android.app.Activity;
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(R.id.editText1);
button = (Button) findViewById(R.id.button1);

* 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.

Popular posts from this blog

Async Task in Android

Shake effect in Android

Example For ListView Using BaseAdapter