Tuesday, 25 August 2015

OnclickProperties Using Button

activity_main.xml
--------------------
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity">

    <Button

      android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Button"

        android:id="@+id/button"

        android:layout_marginTop="77dp"

        android:onClick="show"

        android:layout_alignParentTop="true"

        android:layout_centerHorizontal="true" />

</RelativeLayout>

MainActivity.Java
----------------------
package com.anil.android.onclickpropertiesusingbutton;



import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.Toast;



public class MainActivity extends AppCompatActivity {



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

    }
   //call method name
    public void show(View v)    
Toast.makeText(getApplicationContext(),"My Button isWorking",5000).show();

    }

}

Output is :
-------------








No comments:

Post a Comment