title: Dynamically adding custom row to listview
body: <p>By referring this, I created following:</p>
  
  <p><strong>main.xml</strong></p>
  
  <pre><code>&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;Button
          android:id="@+id/addBtn"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:onClick="addItems"
          android:text="Add New Item" /&gt;
  
      &lt;ListView
          android:id="@+id/list"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:drawSelectorOnTop="false" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
      ListView list;   
      ArrayList&lt;String&gt; listItems = new ArrayList&lt;String&gt;();    
      ArrayAdapter&lt;String&gt; adapter;   
      int clickCounter = 0;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          list = (ListView) findViewById(R.id.list);
          adapter = new ArrayAdapter&lt;String&gt;(this,
                  android.R.layout.simple_list_item_1, listItems);
          list.setAdapter(adapter);
  
          list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                      int position, long id) {
                  String item = list.getItemAtPosition(position).toString();
                  Log.i("MainActivity", "Selected = " + item);
              }
          });
      }
  
      public void addItems(View v) {
          listItems.add("Clicked : " + clickCounter++);
          adapter.notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <hr>
  
  <p>And it's working perfectly. But as per requirements, my each <em>listview row</em> won't just be a single string. Instead, it'll be collection of views consisting of imageview and textviews stored in <em>row.xml</em>.</p>
  
  <p>Now my queries are:</p>
  
  <ul>
  <li><p>What will replace <code>adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, listItems);</code> ? Will it be <code>adapter = new ArrayAdapter&lt;String&gt;(this,R.layout.row, listItems);</code> ??</p></li>
  <li><p>How do I refer to imageview and textviews of each row? How do I set and get data from them? How do I recognize their click events?</p></li>
  <li><p>Is use of <code>Adapter</code> must? or can I get away with it?</p></li>
  </ul>
  
  <p>Any help appreciated.</p>