Advertisement
am_dot_com

DDM20211019

Oct 19th, 2021 (edited)
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 2.00 KB | None | 0 0
  1. package com.joythis.android.fourcorners;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.os.Bundle;
  6. import android.util.Log; //for statements like Log.e(...)
  7. import android.view.View; //for the View datatype
  8. import android.widget.Button; //here via ALT+ENTER
  9. import android.widget.Toast;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.     //ALT+ENTER > "import class" > import android.widget.Button;
  13.     //Class data members
  14.     Button mBtnULC=null, mBtnURC=null, mBtnLLC=null, mBtnLRC=null; //cascade declaration
  15.  
  16.     public static final String ERROR_STAMP = "NULL OBJECT";
  17.  
  18.     @Override
  19.     protected void onCreate(Bundle savedInstanceState) {
  20.         super.onCreate(savedInstanceState);
  21.         //setContentView(R.layout.activity_main);
  22.         //CTRL+SPACE - all available autocomplete options
  23.         setContentView(R.layout.rl_four_corners_v2);
  24.  
  25.         init();
  26.     }//onCreate
  27.  
  28.     public void someMethodInTheActivityClass (View pV){
  29.         Toast t = Toast.makeText(
  30.             this,
  31.             "hello",
  32.             Toast.LENGTH_LONG
  33.         );
  34.         t.show();
  35.     }//someMethodInTheActivityClass
  36.  
  37.     void init(){
  38.         //1 - bindings between XML elements and class data members
  39.         //get rid of the null status
  40.         mBtnULC = findViewById(R.id.idBtnULC);
  41.         mBtnLRC = findViewById(R.id.idBtnLRC);
  42.         mBtnLLC = findViewById(R.id.idBtnLLC);
  43.         mBtnLRC = findViewById(R.id.idBtnLRC);
  44.  
  45.         //quality control
  46.         Button[] aRelevantButtons = {
  47.             mBtnLLC, mBtnLRC, mBtnLLC, mBtnLRC
  48.         };
  49.         for (Button b : aRelevantButtons){
  50.             boolean bNull = b==null;
  51.             if (bNull){
  52.                 Log.e(
  53.                     ERROR_STAMP,
  54.                     "Button found null. Aborting."
  55.                 );
  56.                 finish(); //terminates the Activity
  57.             }//if
  58.         }//for
  59.  
  60.         //2 - via the Java bindings, assign behavior to the XML elements
  61.     }//init
  62. }//MainActivity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement