Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 4.59 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. private OnClickListener clickFunction = new OnClickListener(){stmt; }
  2. package com.example.android.accelerometerplay;
  3.  
  4. import android.app.Activity;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.os.Bundle;
  8. import android.widget.Button;
  9. import android.widget.Toast;
  10. import android.content.Context;
  11.  
  12. public class StudentFormsActivity extends Activity {
  13.     /** Called when the activity is first created. */
  14.     @Override
  15.     public void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.         setContentView(R.layout.main);
  18.  
  19.         // To specify the actions of the Buttons
  20.         Button accept = (Button) findViewById(R.id.myButton1);
  21.         Button reject = (Button) findViewById(R.id.myButton2);
  22.  
  23.         accept.setOnClickListener(clickFunction);
  24.         reject.setOnClickListener(clickFunction);
  25.     }
  26.  
  27.     private OnClickListener clickFunction = new OnClickListener(){
  28.         public void onClick(View v){
  29.             Context context = getApplicationContext();
  30.             CharSequence text;
  31.  
  32.             switch(v.getId()){
  33.                case R.id.myButton1: text="accept was pushed";
  34.                                     break;
  35.                case R.id.myButton2: text="reject was pushed";
  36.                                     break;
  37.                default: text="We didn't know what was pressed :(";  
  38.             }
  39.  
  40.             int duration = Toast.LENGTH_SHORT;
  41.             Toast toast = Toast.makeText(context,text,duration);
  42.             toast.show();
  43.  
  44.         }
  45.     }
  46.  }
  47.        
  48. <?xml version="1.0" encoding="utf-8"?>
  49. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  50.     android:orientation="vertical"
  51.     android:layout_width="fill_parent"
  52.     android:layout_height="fill_parent"
  53.     >
  54. <TextView
  55.     android:id="@+id/myLabel"
  56.     android:text="Name of the student:"
  57.     android:layout_width="fill_parent"
  58.     android:layout_height="wrap_content"
  59.     />
  60. <EditText
  61.     android:id="@+id/myText"
  62.     android:layout_width="fill_parent"
  63.     android:layout_height="wrap_content"
  64.     android:layout_below="@id/myLabel"
  65.     />
  66. <Button
  67.     android:id="@+id/myButton1"
  68.     android:text="Accept:"
  69.     android:textColor="#00FF00"
  70.     android:layout_width="fill_parent"
  71.     android:layout_height="wrap_content"
  72.     android:layout_below="@id/myText"
  73.     android:layout_alignParentRight="true"
  74.     />
  75. <Button
  76.     android:id="@+id/myButton2"
  77.     android:text="Reject:"
  78.     android:textColor="#FF0000"
  79.     android:layout_width="fill_parent"
  80.     android:layout_height="wrap_content"
  81.     android:layout_toLeftOf="@id/myButton1"
  82.     android:layout_alignTop="@id/myButton1"
  83.     />
  84. </RelativeLayout>
  85.        
  86. package com.example.android.accelerometerplay;
  87.  
  88.     import android.app.Activity;
  89.     import android.view.View;
  90.     import android.view.View.OnClickListener;
  91.     import android.os.Bundle;
  92.     import android.widget.Button;
  93.     import android.widget.Toast;
  94.     import android.content.Context;
  95.  
  96.     public class StudentFormsActivity extends Activity {
  97.     /** Called when the activity is first created. */
  98. @Override
  99. public void onCreate(Bundle savedInstanceState) {
  100.     super.onCreate(savedInstanceState);
  101.     setContentView(R.layout.main);
  102.  
  103.     // To specify the actions of the Buttons
  104.     Button accept = (Button) findViewById(R.id.myButton1);
  105.     Button reject = (Button) findViewById(R.id.myButton2);
  106.  
  107.     accept.setOnClickListener(clickFunction);
  108.     reject.setOnClickListener(clickFunction);
  109. }
  110.  
  111. private OnClickListener clickFunction = new OnClickClass();
  112.  
  113. private class OnClickClass implements OnClickListener{
  114.     public void onClick(View v){
  115.         Context context = getApplicationContext();
  116.         CharSequence text;
  117.  
  118.         switch(v.getId()){
  119.            case R.id.myButton1: text="accept was pushed";
  120.                                 break;
  121.            case R.id.myButton2: text="reject was pushed";
  122.                                 break;
  123.            default: text="We didn't know what was pressed :(";  
  124.         }
  125.  
  126.         int duration = Toast.LENGTH_SHORT;
  127.         Toast toast = Toast.makeText(context,text,duration);
  128.         toast.show();
  129.  
  130.     }
  131.  }
  132. }
  133.        
  134. private OnClickListener clickFunction = new OnClickListener(){stmt; }
  135.        
  136. //declaring member class
  137. private OnClickListener clickFunction;
  138.  
  139. private OnClickListener clickFunctionMake(){
  140.     return new OnClickListener(){stmt; };
  141. }
  142.  
  143.  @Override
  144.     public void onCreate(Bundle savedInstanceState) {
  145.         super.onCreate(savedInstanceState);
  146.         setContentView(R.layout.main);
  147. //.....initializing member class
  148.         clickFunction=clickFunctionMake();
  149. ///....
  150. }
  151.        
  152. private OnClickListener clickFunction = new OnClickListener(){stmt; }