Wiring Up Widgets
Now that the buttons have resource IDs, you can access them in QuizActivity. The first step is to add two member variables.
Type the following code into QuizActivity.java. (Do not use code completion; type it in yourself.) After you save the file, it will report two errors.
Listing 1.7 Adding member variables (QuizActivity.java
)
public class QuizActivity extends AppCompatActivity { private Button mTrueButton; private Button mFalseButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_quiz); } }
You will fix the errors in just a second. First, notice the m prefix on the two member (instance) variable names. This prefix ...
Get Android Programming: The Big Nerd Ranch Guide, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.