daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public OnClickListener NewRowButtonListener = new OnClickListener()
  2.    {
  3.       @Override
  4.       public void onClick(View v)
  5.       {              
  6.           AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  7.           builder.setView(getLayoutInflater().inflate(R.layout.custom_dialog_add, null));
  8.           builder.create();
  9.  
  10.           AlertDialog Custom_dialog_add = builder.create();
  11.           Custom_dialog_add.show(); // show the Dialog
  12.  
  13.           Button CancelButton = (Button) findViewById(R.id.CancelButton);
  14.           CancelButton.setOnClickListener(new View.OnClickListener() {      
  15.               @Override
  16.               public void onClick(View v) {Custom_dialog_add.cancel();}  //WRONG: Cannot refer to a non-final variable Custom_dialog_add inside an inner class defined in a different method
  17.             });        
  18.       }
  19.    };
  20.    
  21. public OnClickListener NewRowButtonListener = new OnClickListener()
  22.        {
  23.           @Override
  24.           public void onClick(View v)  
  25.           {
  26.               AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
  27.               dialog.setView(getLayoutInflater().inflate(R.layout.custom_dialog_add, null));
  28.               dialog.create();
  29.  
  30.                final AlertDialog test = dialog.create();
  31.                test.show();
  32.  
  33.                Button close = (Button) findViewById(R.id.CancelButton);
  34.                close.setOnClickListener(new android.view.View.OnClickListener() {
  35.                    public void onClick(View v) {
  36.                        test.dismiss();
  37.                    }
  38.                });
  39.           }
  40.        };
  41.    
  42. 09-28 20:15:19.505: E/AndroidRuntime(25847): FATAL EXCEPTION: main
  43. 09-28 20:15:19.505: E/AndroidRuntime(25847): java.lang.NullPointerException
  44. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at com.pearappx.gamescore3.MainActivity$4.onClick(MainActivity.java:422)
  45. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at android.view.View.performClick(View.java:3627)
  46. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at android.view.View$PerformClick.run(View.java:14329)
  47. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at android.os.Handler.handleCallback(Handler.java:605)
  48. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at android.os.Handler.dispatchMessage(Handler.java:92)
  49. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at android.os.Looper.loop(Looper.java:137)
  50. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at android.app.ActivityThread.main(ActivityThread.java:4511)
  51. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at java.lang.reflect.Method.invokeNative(Native Method)
  52. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at java.lang.reflect.Method.invoke(Method.java:511)
  53. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
  54. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
  55. 09-28 20:15:19.505: E/AndroidRuntime(25847):    at dalvik.system.NativeStart.main(Native Method)
  56.    
  57. LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  58.         View view = inflater.inflate(R.layout.custom_layout, null);
  59.         AlertDialog.Builder dialog = new AlertDialog.Builder(this);
  60.         dialog.setTitle("dialog");
  61.         dialog.setView(view);
  62.         final AlertDialog test = dialog.create();
  63.  
  64.  
  65.         Button close = (Button) view.findViewById(R.id.close_button);
  66.         close.setOnClickListener(new android.view.View.OnClickListener() {
  67.             public void onClick(View v) {
  68.                 test.dismiss();
  69.  
  70.             }
  71.         });
  72.    
  73. //Create new alert dialog
  74.     AlertDialog.Builder dialog = new AlertDialog.Builder(this);
  75.     //set title
  76.     dialog.setTitle("title");
  77.     //create the dialog in a final context
  78.     final AlertDialog test = dialog.create();
  79.     //inflate the custom layout in to a View object
  80.     View view = getLayoutInflater().inflate(R.layout.custom_dialog_add, null);
  81.  
  82.     //find the Button object within the inflated view
  83.     //                       ↓↓↓
  84.     Button close = (Button) view.findViewById(R.id.CancelButton);
  85.     //set the onClickListener
  86.     close.setOnClickListener(new OnClickListener() {
  87.         public void onClick(View v) {
  88.             test.dismiss();
  89.         }
  90.     });
  91.     //show the dialog
  92.     test.show();
  93.    
  94. DialogInterface.OnClickListener cancel = new DialogInterface.OnClickListener() {            
  95.         public void onClick(DialogInterface dialog, int which) {
  96.             // TODO Auto-generated method stub
  97.  
  98.             1 add = 1.this;
  99.             add.finish();
  100.  
  101.             Intent showActivity = new Intent(1.this, 2.class);
  102.             1.this.startActivity(showActivity);
  103.  
  104.         }
  105.     };
  106.    
  107. // creates Dialogs for this Activity
  108.    @Override
  109.    protected Dialog onCreateDialog(int id) {
  110.        final Dialog dialog;
  111.        switch(id) {
  112.        case DIALOG_REALLY_EXIT_ID:
  113.            dialog = new AlertDialog.Builder(this).setMessage(
  114.                                "Do you really want to exit this activity?")
  115.            .setTitle("Exit activity")                    
  116.            .setCancelable(false)
  117.            .setPositiveButton("Yes",
  118.                    new DialogInterface.OnClickListener() {
  119.                public void onClick(DialogInterface dialog, int id) {
  120.                 //add your code you would like to be execute when clicking "yes"
  121.                 //for example the below to exit your activity
  122.                     //Main.this.finish();
  123.                }
  124.            })
  125.            .setNegativeButton("No",
  126.                    new DialogInterface.OnClickListener() {
  127.                public void onClick(DialogInterface dialog, int id) {
  128.                    dialog.cancel(); //to dismiss this dialog
  129.            //add any additional things you would like to execute when pressing the no button
  130.  
  131.                }
  132.            }).create();
  133.            break;
  134.        default:
  135.            dialog = null;
  136.        }
  137.        return dialog;
  138.    }
  139.    
  140. youractivity.this.finish()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top