Step1: 添加相应的资源文件(例如strings.xml)
<string name="true_button">True</string> <string name="false_button">False</string>
Step2:修改相应的Layout文件(注意布局文件中对资源文件的引用[@string/true_button])
<Button android:id="@+id/true_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/true_button" />
Tips: Notice that there is a + sign in the values for android:id but not in the values for android:text. This
is because you are creating the IDs and only referencing the strings. (注意这里的+号,代表你需要创建相应的实体对象。)
Step3: 在Controller中添加相应的实体对象以及逻辑(QuizActivity)
private Button mTrueButton; private Button mFalseButton;
mTrueButton = (Button) findViewById(R.id.true_button); mTrueButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { checkAnswer(true); } });