|
| 1 | +package com.example.android.sunshine.app; |
| 2 | + |
| 3 | +import android.os.Bundle; |
| 4 | +import android.support.v4.app.Fragment; |
| 5 | +import android.support.v7.app.ActionBarActivity; |
| 6 | +import android.view.LayoutInflater; |
| 7 | +import android.view.Menu; |
| 8 | +import android.view.MenuItem; |
| 9 | +import android.view.View; |
| 10 | +import android.view.ViewGroup; |
| 11 | + |
| 12 | + |
| 13 | +public class MainActivity extends ActionBarActivity { |
| 14 | + |
| 15 | + @Override |
| 16 | + protected void onCreate(Bundle savedInstanceState) { |
| 17 | + super.onCreate(savedInstanceState); |
| 18 | + setContentView(R.layout.activity_main); |
| 19 | + if (savedInstanceState == null) { |
| 20 | + getSupportFragmentManager().beginTransaction() |
| 21 | + .add(R.id.container, new PlaceholderFragment()) |
| 22 | + .commit(); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + |
| 27 | + @Override |
| 28 | + public boolean onCreateOptionsMenu(Menu menu) { |
| 29 | + // Inflate the menu; this adds items to the action bar if it is present. |
| 30 | + getMenuInflater().inflate(R.menu.main, menu); |
| 31 | + return true; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public boolean onOptionsItemSelected(MenuItem item) { |
| 36 | + // Handle action bar item clicks here. The action bar will |
| 37 | + // automatically handle clicks on the Home/Up button, so long |
| 38 | + // as you specify a parent activity in AndroidManifest.xml. |
| 39 | + int id = item.getItemId(); |
| 40 | + if (id == R.id.action_settings) { |
| 41 | + return true; |
| 42 | + } |
| 43 | + return super.onOptionsItemSelected(item); |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * A placeholder fragment containing a simple view. |
| 48 | + */ |
| 49 | + public static class PlaceholderFragment extends Fragment { |
| 50 | + |
| 51 | + public PlaceholderFragment() { |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, |
| 56 | + Bundle savedInstanceState) { |
| 57 | + View rootView = inflater.inflate(R.layout.fragment_main, container, false); |
| 58 | + return rootView; |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments