title: How to use onCreateView of AppCompatActivity
body: <p><strong>Background Info:</strong> I currently have an AppCompatActivity which is working. But right now, everything is in the <code>onCreate</code> method. I am concerned it is causing some little bugs I've been having lately with my PagerAdapter having <code>java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged!</code> The bugs only happen when I switch activities back and forth very fast. I wonder if fixing this will fix the bug. </p>
  
  <p><strong>System requirements:</strong>  Min SDK: 15, Target SDK: 23 (at the time of this writing, or whatever is most current)</p>
  
  <p><strong>Question:</strong> How do I move my user interface initialization code into the <code>onCreateView</code> method?</p>
  
  <p>I am familiar with how to implement the <code>onCreate</code> method of <code>android.support.v4.app.Fragment</code>, like this:</p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
  {
      View rootView = inflater.inflate(R.layout.fragment_songdetail, container, false);
      rootView.findViewById(R.id.info).setVisibility(View.INVISIBLE);
  
      return rootView;
  }
  </code></pre>
  
  <p>But there are no options like that for AppCompatActivity. These are my options, from the <a href="http://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html#onCreate(android.os.Bundle)" rel="nofollow">AppCompatActivity</a> docs:</p>
  
  <blockquote>
    <p>View  onCreateView(String name, Context context, AttributeSet attrs)</p>
    
    <p>View  onCreateView(View parent, String name, Context context,
    AttributeSet attrs)</p>
  </blockquote>
  
  <p><strong>Here is my code:</strong>
   (I omitted the methods besides onCreate and onCreateView)</p>
  
  <pre><code>public class DealPage extends AppCompatActivity
  {
      private Deal deal;
      private Poll poll;
      private Video video;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          RealmDatabase.setRealmInstance(this);
  
          //----------- UNPACK EXTRAS -----------
          String date = getIntent().getExtras().getString(KeyStrings.EXTRA_DATE);
  
          //---------------- PREREQUISITE INITIALIZATION ----------
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_deal_page);
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_with_spinner);
          setSupportActionBar(toolbar);
  
          //------------ Enable "UP" navigation ---------------
          getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
          getDataFromDatabase(date);
  
          //----------------- THEMES AND COLORS ------------------
  
          //Set up colors
          final int backgroundColor = this.deal.getTheme().getBackgroundColor().getColor();
          final int accentColor = this.deal.getTheme().getAccentColor().getColor();
          String themeForeground = this.deal.getTheme().getForeground();
          final int foreground = generateForegroundColor(themeForeground);
          final String foregroundWebView = generateForegroundWebViewString(themeForeground); // This is necessary because HTML does not have an alpha channel.
  
          //Set toolbar colors
          toolbar.setBackgroundColor(accentColor);
          toolbar.setTitleTextColor(backgroundColor);
  
          //Set Page Background Color
          RelativeLayout dealPageBackground = (RelativeLayout) findViewById(R.id.deal_page_background);
          dealPageBackground.setBackgroundColor(backgroundColor);
  
          //----------- INITIALIZE THE ACTUAL DEAL PAGE STUFF ----------------
  
          //Title
          TextView title = (TextView) findViewById(R.id.title);
          title.setText(this.deal.getTitle());
          title.setTextColor(foreground);
  
          //Price
          TextView price = (TextView) findViewById(R.id.price);
          NumberFormat fmt = NumberFormat.getCurrencyInstance();
          price.setText(fmt.format(this.deal.getItems().first().getPrice()));
          price.setTextColor(foreground);
  
          //ViewInBrowser
          setUpViewInBrowserButton(backgroundColor, accentColor);
  
          AndDown andDown = new AndDown();
  
          //Set up "linkColorHTML"
          String linkColorHTML = generateLinkColorHTML(accentColor);
  
          //Features
          setUpFeaturesView(andDown, backgroundColor, linkColorHTML, foregroundWebView);
  
          //More Specs button
          setUpMoreSpecsButton(backgroundColor, foreground, (Spinner) findViewById(R.id.spinner));
  
          //Story Title
          TextView storyTitle = (TextView) findViewById(R.id.story_title);
          storyTitle.setText(this.deal.getStory().getTitle());
          storyTitle.setTextColor(accentColor);
  
          //Story Body
          setUpStoryBody(andDown, backgroundColor, linkColorHTML, foregroundWebView);
  
          //Specs Title
          TextView specsTitle = (TextView) findViewById(R.id.specs_title);
          specsTitle.setText(this.deal.getTitle());
          specsTitle.setTextColor(accentColor);
  
          //Specs
          setUpSpecificationsView(andDown, backgroundColor, linkColorHTML, foregroundWebView);
  
          //Set up ViewPager
          ViewPager viewPager = (ViewPager) findViewById(R.id.photos_view_pager);
          viewPager.setAdapter(new PhotoPagerAdapter(this, this.deal.getPhotos()));
  
          // Setup spinner
          setUpSpinner(accentColor, backgroundColor, toolbar);
      }
  
  
      @Override
      public View onCreateView(String name, Context context, AttributeSet attrs)
      {
          return super.onCreateView(name, context, attrs);
      }
  
  }
  </code></pre>