Android Tutorial Button

Android Button is an android widget that can be pressed to perform some action.
In this android tutorial we are using a simple button example to help you understand how to use android button.

Our android button example uses a TextView, EditText and a Button. Drag and drop them from the palette in your design view.
The user enters data in the EditText field and when he clicks the button the text is displayed in the TextView. In the design view of the .xml file select the button and in properties scroll down to the onClick property and choose the method which you want to get called when the button is pressed. Or use the android:onClick=" " attribute.

Here is the .xml file code of our Android button example.
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="" 
 android:layout_alignParentStart="true" />
 android:layout_marginTop="52dp" />

 android:text="Large Text" 
 android:layout_alignParentStart="true" />
Android button
Java code of our button example
 public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {

    public void onButtonClick(View view){
        EditText eText = (EditText)findViewById(;
        String userText = eText.getText().toString();
        TextView displayEnteredText = (TextView)findViewById(;


So this was a simple android button example you can also use OnClickListener instead of using 
the XML android:onClick attribute.
If you want to use OnClickListener on button then see this tutorial. 
Android Tutorial  OnClickListener