From: Neil Smith Date: Fri, 24 Oct 2014 15:01:09 +0000 (+0100) Subject: Got basic detail view working X-Git-Url: https://git.njae.me.uk/?a=commitdiff_plain;h=8751e0563d9f5863957e37c502c8b749afe8db61;p=Sunshine.git Got basic detail view working --- diff --git a/.idea/libraries/appcompat_v7_19_1_0.xml b/.idea/libraries/appcompat_v7_19_1_0.xml index 7efbfdf..5249baa 100644 --- a/.idea/libraries/appcompat_v7_19_1_0.xml +++ b/.idea/libraries/appcompat_v7_19_1_0.xml @@ -1,8 +1,8 @@ - - + + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2e791e9..d8c7eae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -18,6 +18,14 @@ + + + diff --git a/app/src/main/java/uk/me/njae/sunshine/DetailActivity.java b/app/src/main/java/uk/me/njae/sunshine/DetailActivity.java new file mode 100644 index 0000000..aad043e --- /dev/null +++ b/app/src/main/java/uk/me/njae/sunshine/DetailActivity.java @@ -0,0 +1,72 @@ +package uk.me.njae.sunshine; + +import android.content.Intent; +import android.support.v7.app.ActionBarActivity; +import android.support.v7.app.ActionBar; +import android.support.v4.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.os.Build; +import android.widget.TextView; + +import uk.me.njae.sunshine.R; + +public class DetailActivity extends ActionBarActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_detail); + if (savedInstanceState == null) { + getSupportFragmentManager().beginTransaction() + .add(R.id.container, new PlaceholderFragment()) + .commit(); + } + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.detail, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + if (id == R.id.action_settings) { + return true; + } + return super.onOptionsItemSelected(item); + } + + /** + * A placeholder fragment containing a simple view. + */ + public static class PlaceholderFragment extends Fragment { + + public PlaceholderFragment() { + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + Intent intent = getActivity().getIntent(); + View rootView = inflater.inflate(R.layout.fragment_detail, container, false); + if (intent != null && intent.hasExtra(Intent.EXTRA_TEXT)) { + String forecastStr = intent.getStringExtra(Intent.EXTRA_TEXT); + ((TextView) rootView.findViewById(R.id.detail_text)) + .setText(forecastStr); + } + return rootView; + } + } +} diff --git a/app/src/main/java/uk/me/njae/sunshine/ForecastFragment.java b/app/src/main/java/uk/me/njae/sunshine/ForecastFragment.java index 7a3eedf..7a52d35 100644 --- a/app/src/main/java/uk/me/njae/sunshine/ForecastFragment.java +++ b/app/src/main/java/uk/me/njae/sunshine/ForecastFragment.java @@ -1,5 +1,6 @@ package uk.me.njae.sunshine; +import android.content.Intent; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -11,8 +12,10 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; +import android.widget.Toast; import org.json.JSONArray; import org.json.JSONException; @@ -91,8 +94,17 @@ public class ForecastFragment extends Fragment { View rootView = inflater.inflate(R.layout.fragment_main, container, false); - ListView list_view = (ListView) rootView.findViewById(R.id.listview_forecast); - list_view.setAdapter(mForecastAdapter); + ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); + listView.setAdapter(mForecastAdapter); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int position, long l) { + String forecast = mForecastAdapter.getItem(position); + Intent intent = new Intent(getActivity(), DetailActivity.class) + .putExtra(Intent.EXTRA_TEXT, forecast); + startActivity(intent); + } + }); return rootView; } diff --git a/app/src/main/res/layout/activity_detail.xml b/app/src/main/res/layout/activity_detail.xml new file mode 100644 index 0000000..e0182a8 --- /dev/null +++ b/app/src/main/res/layout/activity_detail.xml @@ -0,0 +1,7 @@ + diff --git a/app/src/main/res/layout/fragment_detail.xml b/app/src/main/res/layout/fragment_detail.xml new file mode 100644 index 0000000..4b4625a --- /dev/null +++ b/app/src/main/res/layout/fragment_detail.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/app/src/main/res/menu/detail.xml b/app/src/main/res/menu/detail.xml new file mode 100644 index 0000000..15e27a0 --- /dev/null +++ b/app/src/main/res/menu/detail.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e2edbfa..07620e8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5,5 +5,6 @@ Hello world! Settings Refresh + DetailActivity