CRTC Electronics

Click here to edit subtitle

Reading Buttons

Pushing and Pulling, two ways to read a button


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(;



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_;


runButton_ = (ToggleButton)findViewById(;


   new View.OnClickListener()



      public void onClick(View v)


         toast("button clicked");





make three buttons, each with it's own toast