Done lesson 3.08
[Sunshine.git] / app / src / main / java / uk / me / njae / sunshine / DetailActivity.java
1 package uk.me.njae.sunshine;
2
3 import android.content.Intent;
4 import android.os.Bundle;
5 import android.support.v4.app.Fragment;
6 import android.support.v7.app.ActionBarActivity;
7 import android.view.LayoutInflater;
8 import android.view.Menu;
9 import android.view.MenuItem;
10 import android.view.View;
11 import android.view.ViewGroup;
12 import android.widget.TextView;
13
14 public class DetailActivity extends ActionBarActivity {
15
16 @Override
17 protected void onCreate(Bundle savedInstanceState) {
18 super.onCreate(savedInstanceState);
19 setContentView(R.layout.activity_detail);
20 if (savedInstanceState == null) {
21 getSupportFragmentManager().beginTransaction()
22 .add(R.id.container, new PlaceholderFragment())
23 .commit();
24 }
25 }
26
27
28 @Override
29 public boolean onCreateOptionsMenu(Menu menu) {
30 // Inflate the menu; this adds items to the action bar if it is present.
31 getMenuInflater().inflate(R.menu.detail, menu);
32 return true;
33 }
34
35 @Override
36 public boolean onOptionsItemSelected(MenuItem item) {
37 // Handle action bar item clicks here. The action bar will
38 // automatically handle clicks on the Home/Up button, so long
39 // as you specify a parent activity in AndroidManifest.xml.
40 int id = item.getItemId();
41 if (id == R.id.action_settings) {
42 startActivity(new Intent(this, SettingsActivity.class));
43 }
44 return super.onOptionsItemSelected(item);
45 }
46
47 /**
48 * A placeholder fragment containing a simple view.
49 */
50 public static class PlaceholderFragment extends Fragment {
51
52 public PlaceholderFragment() {
53 }
54
55 @Override
56 public View onCreateView(LayoutInflater inflater, ViewGroup container,
57 Bundle savedInstanceState) {
58 Intent intent = getActivity().getIntent();
59 View rootView = inflater.inflate(R.layout.fragment_detail, container, false);
60 if (intent != null && intent.hasExtra(Intent.EXTRA_TEXT)) {
61 String forecastStr = intent.getStringExtra(Intent.EXTRA_TEXT);
62 ((TextView) rootView.findViewById(R.id.detail_text))
63 .setText(forecastStr);
64 }
65 return rootView;
66 }
67 }
68 }