Example 1:

Example 1:

Open 'main.xml' from layout folder.
Then from toolbox add,
1.EditText
2.Button
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. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

/**
* 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() {

@Override
public void onClick(View arg0) {
Toast.makeText(MyFirstAndroidProjectActivity.this,
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

Shake effect in Android

Example For ListView Using BaseAdapter

Async Task in Android