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 auto-complete; type it in yourself.) After you save the file, it will report two errors.
Listing 1.8 Adding member variables (QuizActivity.java
)
public class QuizActivity extends Activity { private Button mTrueButton; private Button mFalseButton; @Override public 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 is an Android naming convention ...
Get Android Programming: The Big Nerd Ranch Guide 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.