Demo:
1)main.xml:
<?xml version="1.0" encoding="utf-8"?>
1)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:background="#5F04B4"
android:orientation="vertical"
>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="20dp"
android:layout_marginTop="100dp"
android:text="Click Me"
/>
</LinearLayout>
2)Activity:
package
com.venky.buttonanonymusinnertype;
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
ButtonAnonymusInnerTypeActivity extends Activity {
/** Called when the activity is first
created. */
Button button;
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//set the UI
button = (Button) findViewById(R.id.button);
//Write a Listener for Button
button.setOnClickListener(new
OnClickListener() {
public void onClick(View v)
{
// TODO
Auto-generated method stub
Toast.makeText(getApplicationContext(),
"Button
Clicked",
Toast.LENGTH_LONG).show();
}
});
}
}
3)Download this Project Click Here
Thank you for this info
ReplyDelete