Pages

Wednesday, March 20, 2013

Button

Project Name : Button
Application Name : Button
Package Name : com.demo.button
Activity Name : ButtonActivity


Main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>

ButtonActivity.java


package com.demo.button;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class ButtonActivity extends Activity implements OnClickListener{

Button b;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        b = (Button)findViewById(R.id.button1);
        b.setOnClickListener(this);
    }
@Override
public void onClick(View v) {
// TODO Auto-generated method stub

Toast.makeText(getApplicationContext(), "Button pressed..", 10).show();

}
}



No comments:

Post a Comment