We add switch case and find the id of the button that

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: of button1. Now we need to add the reference to button2. Rename the reference of button1 as btn1 and add the following code which will update the reference of button2. // gives us the reference to the button Button btn2 = (Button) findViewById(R.id.button2); // react to user's clicking of the button btn2.setOnClickListener(this); 11. We need to update the onClick() method in order to check which button has been clicked and which action will be taken after clicking. For your convenience, we rename the View parameter "arg0" as "v" of the onClick() method. We add switch case and find the ID of the button that has been clicked by getId() method and enclose the activity calling code fragment within switch block in the following way. switch(v.getId()){ // add the name to the intent...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online