title: Difference between wrap_content and match_parent while using in list view
body: <p>I have a list view with textview inflated by custom adapter. My question is what is the difference if I'm creating a listview with height and width <code>wrap_content</code> and with <code>match_parent</code>.</p>
  
  <p>Here I'm adding my code.</p>
  
  <p><strong>activity_main.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" &gt;
  
      &lt;ListView
          android:id="@+id/list"
          android:layout_width="wrap_content/match_parent"
          android:layout_height="wrap_content/match_parent" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>list_item.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/label"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:padding="10dip"
          android:textSize="16sp"
          android:textStyle="bold" &gt;
  &lt;/TextView&gt;
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity
  {
      public static final String[] titles = new String[]
      { "Facebook", "Twitter" };
      ListView listView;
      List&lt;RowItem&gt; rowItems;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          rowItems = new ArrayList&lt;RowItem&gt;();
          for (int i = 0; i &lt; titles.length; i++)
          {
              RowItem item = new RowItem(titles[i]);
              rowItems.add(item);
          }
  
          listView = (ListView) findViewById(R.id.list);
          CustomListViewAdapter adapter = new CustomListViewAdapter(this,
                  R.layout.list_item, rowItems);
          listView.setAdapter(adapter);
  
      }
  
  }
  </code></pre>
  
  <p><strong>RowItem.java</strong></p>
  
  <pre><code>public class RowItem
  {
      private String title;
  
      public RowItem(String title)
      {
          this.title = title;
      }
  
      public String getTitle()
      {
          return title;
      }
  
      public void setTitle(String title)
      {
          this.title = title;
      }
  
      @Override
      public String toString()
      {
          return title;
      }
  }
  </code></pre>
  
  <p><strong>CustomListViewAdapter.java</strong></p>
  
  <pre><code>public class CustomListViewAdapter extends ArrayAdapter&lt;RowItem&gt; {
  
      Context context;
  
      public CustomListViewAdapter(Context context, int resourceId,
              List&lt;RowItem&gt; items) {
          super(context, resourceId, items);
          this.context = context;
      }
  
      /*private view holder class*/
      private class ViewHolder {
          TextView txtTitle;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          ViewHolder holder = null;
          RowItem rowItem = getItem(position);
  
          LayoutInflater mInflater = (LayoutInflater) context
                  .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
          if (convertView == null) {
              convertView = mInflater.inflate(R.layout.list_item, null);
              holder = new ViewHolder();
              holder.txtTitle = (TextView) convertView.findViewById(R.id.label);
              Log.i("ListView",holder.txtTitle.toString());
              convertView.setTag(holder);
          } else
              holder = (ViewHolder) convertView.getTag();
  
          holder.txtTitle.setText(rowItem.getTitle());
  
          return convertView;
      }
  }
  </code></pre>
  
  <p>Here I've a line <code>Log.i("ListView",holder.txtTitle.toString());</code> which is displaying more logs than the listview items inflated using <code>wrap_content</code>, while displaying completely perfect using <code>match_parent</code>.</p>
  
  <p>Here is the <strong>LogCat</strong>:</p>
  
  <ul>
  <li><p>LogCat for listview with <strong>width</strong> and <strong>height</strong> equals to <code>wrap_content</code></p>
  
  <blockquote>
    <p>05-01 16:59:49.817: I/ListView(545): android.widget.TextView@43e45020 <br>
    05-01 16:59:49.867: I/ListView(545): android.widget.TextView@43e46350 <br>
    05-01 16:59:49.897: I/ListView(545): android.widget.TextView@43e47ce0 <br></p>
  </blockquote></li>
  <li><p>LogCat for listview with <strong>width</strong> and <strong>height</strong> equals to <code>match_parent</code></p>
  
  <blockquote>
    <p>05-01 16:58:49.037: I/ListView(501): android.widget.TextView@43e526c8 <br>
    05-01 16:58:49.088: I/ListView(501): android.widget.TextView@43e52f08 <br></p>
  </blockquote></li>
  </ul>