Screen Shots:
activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Developed by Shrikant"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Button
android:id="@+id/clickButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Click Me"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:textSize="20dp"
/>
</LinearLayout>
MainActivity.java:
package com.shrikant.workingwithbutton;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button clickbtn=(Button)findViewById(R.id.clickButton);
clickbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), "Button is clicked", Toast.LENGTH_SHORT).show();
}
});
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.