How to perform button operation in android & add Button events By WeRCopyPasteDeveloper

                                


                                                      activity_main.xml


<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
 xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:app="http://schemas.android.com/apk/res-auto" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent"     
 android:orientation="vertical" 
 android:layout_height="match_parent" 
 tools:context=".MainActivity">
    <Button 
    android:id="@+id/b1" 
    android:layout_width="wrap_content"         
    android:layout_height="wrap_content"         
    android:layout_alignParentBottom="true"         
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="235dp" 
    android:gravity="center" 
    android:text="SHOW" /> 
</RelativeLayout>



                                                 Main_Activivity.java


package com.spam.madhav.buttonexp;
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
Button b1;


    @Override     
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);         
        setContentView(R.layout.activity_main); 
        b1=(Button)findViewById(R.id.b1); 
        b1.setOnClickListener(new View.OnClickListener() {
        @Override 
         public void onClick(View v) {
        Toast.makeText(getApplicationContext(),"CopyPasteDeveloper",Toast.LENGTH_LONG)
        .show();     
        }
      });
     }
}

How to perform button operation in android & add Button events By WeRCopyPasteDeveloper





       

No comments:

Post a Comment