Last active
February 2, 2016 21:31
-
-
Save robbiemu/7cac9295faf2d8d367ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" | |
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" | |
android:paddingRight="@dimen/activity_horizontal_margin" | |
android:paddingTop="@dimen/activity_vertical_margin" | |
android:paddingBottom="@dimen/activity_vertical_margin" | |
tools:context=".MainActivity$PlaceholderFragment" | |
android:background="#0080ff"> | |
<ListView android:id="@+id/listview_forecast" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</FrameLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.android.sunshine.app; | |
import android.support.v7.app.ActionBarActivity; | |
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.widget.ArrayAdapter; | |
import android.widget.ListView; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
public class MainActivity extends ActionBarActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
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.main, 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(); | |
//noinspection SimplifiableIfStatement | |
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 { | |
ArrayAdapter<String> mForecastAdapter; | |
public PlaceholderFragment() { | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
Bundle savedInstanceState) { | |
// just a quick framework for loading this data dynamically | |
/* String day = ""; | |
String skies = ""; | |
int high = 0; | |
int low = 0; */ | |
String [] forecastArray = { | |
/* String.format("%s — %s - %d/%d", day, skies, high, low); */ | |
"Today - sunny - 56/30", | |
"Tomorrow - rainy - 64/38", | |
"Weds - cloudy - 52/32", | |
"Thur - sunny - 45/25" | |
"Fri - part. cloudy - 40/25" | |
"Sat", | |
"Sun etc" | |
}; /* 5 days, prev and next */ | |
List<String> weekForecast = new ArrayList<String>( | |
Arrays.asList(forecastArray) | |
); | |
mForecastAdapter = | |
new ArrayAdapter<String> ( | |
getActivity(), // current context | |
R.layout.list_item_forecast, // id of list item in layout | |
R.id.list_item_forecase_textview, // id of textview to populate | |
weekForecast); // forecast data above | |
View rootView = inflater.inflate(R.layout.fragment_main, container, false); | |
ListView lv = (ListView) rootView.findViewById(R.id.listview_forecast); | |
lv.setAdapter(mForecastAdapter); | |
return rootView; | |
//return inflater.inflate(R.layout.fragment_main, container, false);// — tried this based on another student's work who was also trying to get it to work | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment