title: How to programmatically set the size of the font in the list item before adding it to the ListView?
body: <p>I'm interested in how you can change the size of the text in the list and then add it to the ListView. I'm using a list_item with custom layout . The question is how you can set the size of the text before it gets into the ListView. I hope for your help.</p>
  
  <p><strong>list_item.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      xmlns:android1="http://schemas.android.com/apk/res/android"&gt;
  
  &lt;LinearLayout
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      &gt;
  
      &lt;TextView
          android:id="@+id/shop_name"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="1"
          /&gt;
  
      &lt;TextView
          android:id="@+id/shop_address"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="2"
          /&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>day_list_events.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical"
      android:layout_gravity="center"
      android:id="@+id/layout"
      &gt;
  
  &lt;TextView 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:id="@+id/day_and_data"
      android:text="Перелік клієнтів на сьогоднішній день."
      android:textStyle="bold"
      /&gt;
  
  &lt;TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:id="@+id/help_info"
      android:text="(Щоб отримати інформацію про клієнта та оформити замовлення - натисніть на відповідного клієнта у списку)"
      android:textColor="#A0A0A0"
      /&gt;
  
  &lt;ListView
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:id="@+id/day_list_event"
      &gt;
  
  &lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>DayListEventsActivity.java</strong></p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.HashMap;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.SharedPreferences;
  import android.content.res.Resources;
  import android.os.Bundle;
  import android.view.Window;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  
  public class DayListEventsActivity extends Activity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      super.onCreate(savedInstanceState);
      setContentView(R.layout.day_list_events);
      sharedPreferences = getSharedPreferences("impInfo", Context.MODE_PRIVATE);
      Resources res = this.getResources();
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; dayShopsInfo = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
      String[] shopName = res.getStringArray(R.array.shop_name);
      String[] shopAddress = res.getStringArray(R.array.shop_address);        
      for(int i = 0; i &lt; shopName.length; i++){
          HashMap&lt;String, String&gt; dayShopsInfoCont = new HashMap&lt;String, String&gt;();
          dayShopsInfoCont.put(KEY_SHOP_NAME, shopName[i]);
          dayShopsInfoCont.put(KEY_SHOP_ADDRESS, shopAddress[i]);
          System.out.println(i+" "+shopName[i]+" "+shopAddress[i]);
          dayShopsInfo.add(dayShopsInfoCont);         
      }
      ListView shopList = (ListView)findViewById(R.id.day_list_event);
      SimpleAdapter shopListAdapter = new SimpleAdapter(this,
              dayShopsInfo,
              R.layout.list_item,
              new String[]{KEY_SHOP_NAME, KEY_SHOP_ADDRESS},
              new int[]{R.id.shop_name, R.id.shop_address});
      shopList.setAdapter(shopListAdapter);
      shopList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
  }
  
  private final String KEY_SHOP_NAME = "shop name";
  private final String KEY_SHOP_ADDRESS = "shop address";
  private SharedPreferences sharedPreferences;
  }
  </code></pre>
  
  <p><strong>UPDATE (Solution).</strong></p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.SharedPreferences;
  import android.content.res.Resources;
  import android.os.Bundle;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.Window;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  import android.widget.TextView;
  
  public class DayListEventsActivity extends Activity {
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      super.onCreate(savedInstanceState);
      setContentView(R.layout.day_list_events);
      sharedPreferences = getSharedPreferences("impInfo", Context.MODE_PRIVATE);
      Resources res = this.getResources();
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; dayShopsInfo = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
      String[] shopName = res.getStringArray(R.array.shop_name);
      String[] shopAddress = res.getStringArray(R.array.shop_address);        
      for(int i = 0; i &lt; shopName.length; i++){
          HashMap&lt;String, String&gt; dayShopsInfoCont = new HashMap&lt;String, String&gt;();
          dayShopsInfoCont.put(KEY_SHOP_NAME, shopName[i]);
          dayShopsInfoCont.put(KEY_SHOP_ADDRESS, shopAddress[i]);
          System.out.println(i+" "+shopName[i]+" "+shopAddress[i]);
          dayShopsInfo.add(dayShopsInfoCont);         
      }
      ListView shopList = (ListView)findViewById(R.id.day_list_event);
      MySimpleAdapter shopListAdapter = new MySimpleAdapter(this,
              dayShopsInfo,
              R.layout.list_item,
              new String[]{KEY_SHOP_NAME, KEY_SHOP_ADDRESS},
              new int[]{R.id.shop_name, R.id.shop_address});
      shopList.setAdapter(shopListAdapter);
      shopList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
  }
  
  public class MySimpleAdapter extends SimpleAdapter{
  
      public MySimpleAdapter(Context context,
                              List&lt;? extends Map&lt;String, ?&gt;&gt; data,
                              int resource,
                              String[] from, int[] to) {
          super(context, data, resource, from, to);           
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent){
          View returnView = super.getView(position, convertView, parent);
          TextView shopName = (TextView)returnView.findViewById(R.id.shop_name);
          shopName.setTextSize(20.0f);
          return returnView;
      }
  
  }
  
  private final String KEY_SHOP_NAME = "shop name";
  private final String KEY_SHOP_ADDRESS = "shop address";
  private SharedPreferences sharedPreferences;
  }
  </code></pre>