Class SettingsActivity
(Fig. 5.36) hosts the SettingsFragment
when the app is running in portrait orientation. To create this class, right click the package (com.deitel.flagquiz
) and select New > Class to display the New Java Class dialog. Set the new class’s Name to SettingsActivity
, set its Superclass to android.app.Activity
and click Finish.
1 // SettingsActivity.java
2 // Activity to display SettingsFragment on a phone
3 package com.deitel.flagquiz;
4
5 import android.app.Activity;
6 import android.os.Bundle;
7
8 public class SettingsActivity extends Activity
9 {
10 // use FragmentManager to display SettingsFragment
11 @Override
12 protected void onCreate(Bundle savedInstanceState)
13 {
14 super.onCreate(savedInstanceState);
15 setContentView(R.layout.activity_settings);
16 }
17 } // end class SettingsActivity
Overridden method onCreate
(lines 11–16) calls Activity
method setContentView
to inflate the GUI defined by activity_settings.xml
(Section 5.4.6)—represented by the resource R.layout.activity_settings
.