Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.joythis.android.fourcorners;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log; //for statements like Log.e(...)
- import android.view.View; //for the View datatype
- import android.widget.Button; //here via ALT+ENTER
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- //ALT+ENTER > "import class" > import android.widget.Button;
- //Class data members
- Button mBtnULC=null, mBtnURC=null, mBtnLLC=null, mBtnLRC=null; //cascade declaration
- public static final String ERROR_STAMP = "NULL OBJECT";
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //setContentView(R.layout.activity_main);
- //CTRL+SPACE - all available autocomplete options
- setContentView(R.layout.rl_four_corners_v2);
- init();
- }//onCreate
- public void someMethodInTheActivityClass (View pV){
- Toast t = Toast.makeText(
- this,
- "hello",
- Toast.LENGTH_LONG
- );
- t.show();
- }//someMethodInTheActivityClass
- void init(){
- //1 - bindings between XML elements and class data members
- //get rid of the null status
- mBtnULC = findViewById(R.id.idBtnULC);
- mBtnLRC = findViewById(R.id.idBtnLRC);
- mBtnLLC = findViewById(R.id.idBtnLLC);
- mBtnLRC = findViewById(R.id.idBtnLRC);
- //quality control
- Button[] aRelevantButtons = {
- mBtnLLC, mBtnLRC, mBtnLLC, mBtnLRC
- };
- for (Button b : aRelevantButtons){
- boolean bNull = b==null;
- if (bNull){
- Log.e(
- ERROR_STAMP,
- "Button found null. Aborting."
- );
- finish(); //terminates the Activity
- }//if
- }//for
- //2 - via the Java bindings, assign behavior to the XML elements
- }//init
- }//MainActivity
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement