Skip to content

Commit

Permalink
S04.02-Solution-DisplayDayForecast
Browse files Browse the repository at this point in the history
  • Loading branch information
mlustig authored and Jeremy Silver committed Jan 19, 2017
1 parent caf6e7e commit f294188
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
package com.example.android.sunshine;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

public class DetailActivity extends AppCompatActivity {

private static final String FORECAST_SHARE_HASHTAG = " #SunshineApp";

private String mForecast;
private TextView mWeatherDisplay;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);

// TODO (2) Display the weather forecast that was passed from MainActivity
mWeatherDisplay = (TextView) findViewById(R.id.tv_display_weather);

Intent intentThatStartedThisActivity = getIntent();

// COMPLETED (2) Display the weather forecast that was passed from MainActivity
if (intentThatStartedThisActivity != null) {
if (intentThatStartedThisActivity.hasExtra(Intent.EXTRA_TEXT)) {
mForecast = intentThatStartedThisActivity.getStringExtra(Intent.EXTRA_TEXT);
mWeatherDisplay.setText(mForecast);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public void onClick(String weatherForDay) {
Context context = this;
Class destinationClass = DetailActivity.class;
Intent intentToStartDetailActivity = new Intent(context, destinationClass);
// TODO (1) Pass the weather to the DetailActivity
// COMPLETED (1) Pass the weather to the DetailActivity
intentToStartDetailActivity.putExtra(Intent.EXTRA_TEXT, weatherForDay);
startActivity(intentToStartDetailActivity);
}

Expand Down
9 changes: 8 additions & 1 deletion app/src/main/res/layout/activity_detail.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:padding="8dp">

<TextView
android:id="@+id/tv_display_weather"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="22sp" />

</FrameLayout>

0 comments on commit f294188

Please sign in to comment.