- private OnClickListener clickFunction = new OnClickListener(){stmt; }
- package com.example.android.accelerometerplay;
- import android.app.Activity;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.os.Bundle;
- import android.widget.Button;
- import android.widget.Toast;
- import android.content.Context;
- public class StudentFormsActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // To specify the actions of the Buttons
- Button accept = (Button) findViewById(R.id.myButton1);
- Button reject = (Button) findViewById(R.id.myButton2);
- accept.setOnClickListener(clickFunction);
- reject.setOnClickListener(clickFunction);
- }
- private OnClickListener clickFunction = new OnClickListener(){
- public void onClick(View v){
- Context context = getApplicationContext();
- CharSequence text;
- switch(v.getId()){
- case R.id.myButton1: text="accept was pushed";
- break;
- case R.id.myButton2: text="reject was pushed";
- break;
- default: text="We didn't know what was pressed :(";
- }
- int duration = Toast.LENGTH_SHORT;
- Toast toast = Toast.makeText(context,text,duration);
- toast.show();
- }
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <TextView
- android:id="@+id/myLabel"
- android:text="Name of the student:"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- <EditText
- android:id="@+id/myText"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/myLabel"
- />
- <Button
- android:id="@+id/myButton1"
- android:text="Accept:"
- android:textColor="#00FF00"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_below="@id/myText"
- android:layout_alignParentRight="true"
- />
- <Button
- android:id="@+id/myButton2"
- android:text="Reject:"
- android:textColor="#FF0000"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:layout_toLeftOf="@id/myButton1"
- android:layout_alignTop="@id/myButton1"
- />
- </RelativeLayout>
- package com.example.android.accelerometerplay;
- import android.app.Activity;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.os.Bundle;
- import android.widget.Button;
- import android.widget.Toast;
- import android.content.Context;
- public class StudentFormsActivity extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- // To specify the actions of the Buttons
- Button accept = (Button) findViewById(R.id.myButton1);
- Button reject = (Button) findViewById(R.id.myButton2);
- accept.setOnClickListener(clickFunction);
- reject.setOnClickListener(clickFunction);
- }
- private OnClickListener clickFunction = new OnClickClass();
- private class OnClickClass implements OnClickListener{
- public void onClick(View v){
- Context context = getApplicationContext();
- CharSequence text;
- switch(v.getId()){
- case R.id.myButton1: text="accept was pushed";
- break;
- case R.id.myButton2: text="reject was pushed";
- break;
- default: text="We didn't know what was pressed :(";
- }
- int duration = Toast.LENGTH_SHORT;
- Toast toast = Toast.makeText(context,text,duration);
- toast.show();
- }
- }
- }
- private OnClickListener clickFunction = new OnClickListener(){stmt; }
- //declaring member class
- private OnClickListener clickFunction;
- private OnClickListener clickFunctionMake(){
- return new OnClickListener(){stmt; };
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- //.....initializing member class
- clickFunction=clickFunctionMake();
- ///....
- }
- private OnClickListener clickFunction = new OnClickListener(){stmt; }