title: Add same view multiple times - Reuse a layout
body: <p>I'm developing an app that shows the weather forecast of 4 different regions, 5 days in the future. Every region displays 5 days and every day has its own data: a TextView with the name of the day, a TextView with the main weather condition for that day, an ImageView that shows the weather icon, and two TextView with the min temp and max temp for that day. Like this:</p>
  
  <p><a href="https://i.stack.imgur.com/HDhaZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HDhaZ.png" alt="enter image description here"></a></p>
  
  <p>I implemented this in a SUPER AWFUL layout.xml file, treating each TextView and ImageView for all the 20 days of the 4 regions separately:</p>
  
  <pre><code>&lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;TextView
              android:id="@+id/tv_weather_forecats_title"
              style="@style/tv_weather_11"
              android:text="@string/extended_forecast" /&gt;
  
          &lt;TextView
              android:id="@+id/tv_fore_title_city"
              style="@style/tv_weather_6"
              android:text="@string/title_city" /&gt;
  
          &lt;LinearLayout style="@style/ll_weather_1"&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day1_city"
                      style="@style/tv_weather_7"
                      android:text="Mon"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond1_city"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day1_city"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds" /&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day1_city"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day1_city"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day2_city"
                      style="@style/tv_weather_7"
                      android:text="Tue"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond2_city"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day2_city"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day2_city"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day2_city"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day3_city"
                      style="@style/tv_weather_7"
                      android:text="Wed"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond3_city"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day3_city"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day3_city"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day3_city"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day4_city"
                      style="@style/tv_weather_7"
                      android:text="Thu"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond4_city"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day4_city"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day4_city"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day4_city"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day5_city"
                      style="@style/tv_weather_7"
                      android:text="Fri"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond5_city"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day5_city"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day5_city"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day5_city"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
  
          &lt;View
              android:layout_width="match_parent"
              android:layout_height="1dp"
              android:layout_marginLeft="16dp"
              android:layout_marginRight="16dp"
              android:background="@color/colorDarkTextDivider" /&gt;
  
          &lt;TextView
              android:id="@+id/tv_fore_title_east"
              style="@style/tv_weather_6"
              android:text="@string/title_east" /&gt;
  
          &lt;LinearLayout style="@style/ll_weather_1"&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day1_east"
                      style="@style/tv_weather_7"
                      android:text="Mon"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond1_east"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day1_east"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day1_east"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day1_east"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day2_east"
                      style="@style/tv_weather_7"
                      android:text="Tue"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond2_east"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day2_east"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day2_east"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day2_east"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day3_east"
                      style="@style/tv_weather_7"
                      android:text="Wed"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond3_east"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day3_east"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day3_east"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day3_east"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day4_east"
                      style="@style/tv_weather_7"
                      android:text="Thu"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond4_east"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day4_east"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds" /&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day4_east"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day4_east"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day5_east"
                      style="@style/tv_weather_7"
                      android:text="Fri"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond5_east"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day5_east"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day5_east"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day5_east"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
  
          &lt;View
              android:layout_width="match_parent"
              android:layout_height="1dp"
              android:layout_marginLeft="16dp"
              android:layout_marginRight="16dp"
              android:background="@color/colorDarkTextDivider" /&gt;
  
          &lt;TextView
              android:id="@+id/tv_fore_title_south"
              style="@style/tv_weather_6"
              android:text="@string/title_south" /&gt;
  
          &lt;LinearLayout style="@style/ll_weather_1"&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day1_south"
                      style="@style/tv_weather_7"
                      android:text="Mon"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond1_south"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day1_south"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day1_south"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day1_south"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day2_south"
                      style="@style/tv_weather_7"
                      android:text="Tue"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond2_south"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day2_south"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day2_south"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day2_south"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day3_south"
                      style="@style/tv_weather_7"
                      android:text="Wed"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond3_south"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day3_south"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds" /&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day3_south"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day3_south"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day4_south"
                      style="@style/tv_weather_7"
                      android:text="Thu"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond4_south"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day4_south"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds" /&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day4_south"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day4_south"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
  
              &lt;LinearLayout
                  android:layout_width="0dp"
                  android:layout_height="match_parent"
                  android:layout_weight="1"
                  android:gravity="center_horizontal"
                  android:orientation="vertical"&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_day5_south"
                      style="@style/tv_weather_7"
                      android:text="Fri"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_cond5_south"
                      style="@style/tv_weather_8"
                      android:text="Light Rain"/&gt;
  
                  &lt;ImageView
                      android:id="@+id/iv_fore_ic_day5_south"
                      style="@style/iv_weather_1"
                      android:src="@drawable/ic_main_broken_clouds" /&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_min_day5_south"
                      style="@style/tv_weather_9"
                      android:text="5"/&gt;
  
                  &lt;TextView
                      android:id="@+id/tv_fore_max_day5_south"
                      style="@style/tv_weather_10"
                      android:text="15"/&gt;
              &lt;/LinearLayout&gt;
          &lt;/LinearLayout&gt;
      &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>On the Java file I have 100 declarations of views and use 100 lines to get the instance of the views, and another 100 set methods to set texts and images... I know, super/unbelievably awful. </p>
  
  <p>This must be bad design for sure. There must be a way to put a single view (day name, condition, image, min temp and max temp) in a layout and reuse it. Any idea? </p>