/* This is Simple Button Demo of Android */
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center" >
<Button
android:id="@+id/btnMyClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
</LinearLayout>
ButtonDemoActivity.java
package com.buttondemo;
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 ButtonDemoActivity extends Activity {
/** Called when the activity is first created. */
Button btnMyClick;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnMyClick=(Button)findViewById(R.id.btnMyClick);
btnMyClick.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(ButtonDemoActivity.this, "My Button is Pressed", Toast.LENGTH_LONG).show();
}
});
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center" >
<Button
android:id="@+id/btnMyClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me" />
</LinearLayout>
ButtonDemoActivity.java
package com.buttondemo;
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 ButtonDemoActivity extends Activity {
/** Called when the activity is first created. */
Button btnMyClick;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnMyClick=(Button)findViewById(R.id.btnMyClick);
btnMyClick.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(ButtonDemoActivity.this, "My Button is Pressed", Toast.LENGTH_LONG).show();
}
});
}
}
0 comments:
Post a Comment