Make a custom view from some of the views already in the WeatherFragment. AKA a "compound view".
Approach 1 (e.g. PriceLabelView in the LateRooms project)
Move the views into a new XML file. e.g. weather_view.xml The top-level XML tag should be a <merge/> tag.
Create a new class which extends View. e.g. com.jmuskett.newweather.WeatherView
Inside the constructor for your new view, do LayoutInflater.from(context).inflate(R.layout.weather_view, this); to inflate the XML file make it the content of your View.
Include the layout inside another view by adding a <com.jmuskett.newweather.WeatherView/> element.
Approach 2 (e.g. ProgressView / progress.xml in the LR project)
Create a new class which extends ViewGroup, or more likely one of its subclasses like LinearLayout. e.g. com.jmuskett.newweather.WeatherView2
Move the views into a new XML file. e.g. weather_view2.xml The top-level XML tag should be <com.jmuskett.newweather.WeatherView/>
Include the layout inside another view by adding an <include/> element, with the android:layout value set to the name of your new XML file - e.g. "@layout/weather_view2"
Questions:
What does the merge tag do?
Can you think of any other uses for the include tag?
Which method do you think is better in general? (Not sure there's a right or wrong answer here!)
Make a custom view from some of the views already in the WeatherFragment. AKA a "compound view".
Approach 1 (e.g. PriceLabelView in the LateRooms project)
<merge/>
tag.LayoutInflater.from(context).inflate(R.layout.weather_view, this);
to inflate the XML file make it the content of your View.<com.jmuskett.newweather.WeatherView/>
element.Approach 2 (e.g. ProgressView / progress.xml in the LR project)
<com.jmuskett.newweather.WeatherView/>
<include/>
element, with the android:layout value set to the name of your new XML file - e.g. "@layout/weather_view2"Questions: