Professional Documents
Culture Documents
• <string
name="crime_title_label">Title</string>
• <string
name="crime_details_label">Details</string
>
• <string
name="crime_solved_label">Solved</string>
Adding widget instance variables
(CrimeFragment.java)
• public class CrimeFragment extends Fragment
{
• private Crime mCrime;
• private EditText mTitleField;
• private Button mDateButton;
• private CheckBox mSolvedCheckBox;
Setting Button text (CrimeFragment.java)
• mTitleField.addTextChangedListener(new
TextWatcher() {
• ...
• });
• mDateButton =
(Button)v.findViewById(R.id.crime_date);
• mDateButton.setText(mCrime.getDate().toString());
• mDateButton.setEnabled(false);
• return v;
Listening for CheckBox changes
(CrimeFragment.java)
• mDateButton.setEnabled(false);
• mSolvedCheckBox = (CheckBox)v.findViewById(R.id.crime_solved);
• mSolvedCheckBox.setOnCheckedChangeListener(new
OnCheckedChangeListener() {
• @Override
• public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
• // Set the crime's solved property
• mCrime.setSolved(isChecked);
• }
• });
• return v;
Styles, themes, and theme attributes
• <Button android:id="@+id/crime_date"
• android:layout_width="match_parent"
• android:layout_marginRight="16dp"
• android:padding="80dp"
Creating a landscape layout
• The graphical layout editor can generate the
landscape version of a layout file for you.
Landscape layout for CrimeFragment
Adding a new widget
• Select LinearLayout (Horizontal) and
• drag it to the component tree. Drop this
LinearLayout just above the date button.
Ensure that the new LinearLayout is a child of
the root LinearLayout
Changing LinearLayout’s width and height