build a professional weather app - sunshine
TRANSCRIPT
Building a Professional
WeatherApp
04/04/2015 @MZouinkhi
ISS
ATSo G
oogle
Clu
b
First Session
Smart Phone == Small ComputerLow processing powerLimited RAMLimited data connections ( low bandwidth)Limited battery life
- ListViews / Adapters- Recycler View / CardView - WebServices.- AsyncTasks.- JSON Parsing.- SQLite.- JUnit Tests.
Add new layout XML called list_item_forecast
containing TextView with id=”@+id/
list_item_forecast_textview”
Modify fragment_main- RelativeLayout to FrameLayout- TextView to ListView with:
id=”@+id/listview_forecast”width=”match_parent”height=”match_parent”
Java- create a table of Strings
called forecastArray[] which contains static data :“Today - Sunny - 78/63”, …- Create a list WeekForecast
from forecastArray[] Arrays.asList()
Initialise ArrayAdapterin onCreateView()
ArrayAdapter<String> called mForecastAdapter
contextID of list item layoutID of text Viewlist of data
Initialise ArrayAdapterin onCreateView()
ArrayAdapter<String> called mForecastAdapter with parametrescontext getActivity()ID of list item layout R.layout.liste_item_forecastID of text View R.id.list_item_forecast_textviewlist of data weekForecast
findView of ListView R.id.listview_forecast with name listView
ListView listView= (ListView) this.findViewById(R.id.listview_forecast )
Add a onItemClickListener on listViewOverride onItemClick to show a toast with item text
to get Text: mForecastAdapter.getItem(position); .
Create New Blanc Activity with Fragmentcalled DetailActivity with father
MainActivitywith textView id="@+id/text_detail"
Intent
Intent nameIntent= new Intent(context,Activity.class).putExtra(Intent.EXTRA_TEXT,text); startActivity(nameIntent);
on onCreateView of DetailActivityfind view of textView text_detail
test if you have an extraif yes put the extra String in textView
Intent
if (intent!=null && intent.hasExtra(Intent.EXTRA_TEXT)) { mForecastStr = intent.getStringExtra(Intent.EXTRA_TEXT); ((TextView) rootView.findViewById(R.id.text_detail)) .setText(mForecastStr);
Android is a major step
towards an ethical, user-
controlled, free-software
portable phone, but there is a
long way to go.Richard
stallman