CRTC Electronics

Click here to edit subtitle

Reading Buttons

Pushing and Pulling, two ways to read a button

Pulling

read a button when you want to


1. in MainActivity declare a veriable



2. in onCreate() link the vereble to the button



3. in loop() when needed see if the button is checked

private ToggleButton testButton_;



testButton_ = (ToggleButton)findViewById(R.id.testButton);



testButton_.isChecked()

Pushing

do something when a button is pressed 


1. in MainActivity declare a veriable


2. in onCreate() link the variable to the button
3. in onCreate() turn on the buttons listener 




4. when a button is pressed this function is called

private ToggleButton runButton_;


(onCreate())

runButton_ = (ToggleButton)findViewById(R.id.runButton);

runButton_.setOnClickListener(


   new View.OnClickListener()

   {

      @Override

      public void onClick(View v)

      {

         toast("button clicked");

      }

   }

);

Challeng

make three buttons, each with it's own toast