Screenshots :
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<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="com.chantisandroid.buttonexample.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="clickme"
android:id="@+id/button_click"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="82dp" />
</RelativeLayout>
MainActivity.java :
package com.chantisandroid.buttonexample; 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 implements View.OnClickListener { Button click; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); click = (Button)findViewById(R.id.button_click); click.setOnClickListener(this); } @Override public void onClick(View view) { Toast.makeText(this,"button is working",Toast.LENGTH_LONG).show(); } }
No comments:
Post a Comment