title: How to construct and display the info in simple_list_item_2?
body: <p>I get the list of customer info from my (testing) database, and I want to display it. The customer is represented by the <code>Customer</code> class with <code>name</code>, <code>info</code>, and <code>note</code> members. Its <code>toString</code> method returns only the <code>name</code>. I have created the <code>DemoDatabaseMainActivity</code> that uses the <code>simple_list_item_1</code> layout only, thus displaying only the <code>name</code> of a customer -- like this:</p>
  
  <pre><code>public class DemoDatabaseMainActivity extends ListActivity {
  
      private CustomerDataSource datasource;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          datasource = new CustomerDataSource(this);
          datasource.open();
  
          List&lt;Customer&gt; values = datasource.getAllCustomers();
  
          ArrayAdapter&lt;Customer&gt; adapter = new ArrayAdapter&lt;Customer&gt;(this,
                                     android.R.layout.simple_list_item_1, values);
          setListAdapter(adapter);
      }
  ...
  }
  </code></pre>
  
  <p>It works just fine; however, I'd like to learn the next step...</p>
  
  <p>I would like to modify the code so that I could use the <code>android.R.layout.simple_list_item_2</code> where <code>name</code> would be at the first line, and the <code>info</code> + <code>note</code> at the second line? What should be implemented instead of the <code>Customer.toString()</code>, and what adapter or whatever should I use?</p>
  
  <p><strong>Update</strong> based on Patric's comment <a href="https://stackoverflow.com/a/16062742/1346705">https://stackoverflow.com/a/16062742/1346705</a> -- with respect to that, I have hoped for the modified solution like that:</p>
  
  <pre><code>public class DemoDatabaseMainActivity extends ListActivity {
  
      private CustomerDataSource datasource;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          datasource = new CustomerDataSource(this);
          datasource.open();
  
          List&lt;Customer&gt; values = datasource.getAllCustomers();
  
          TwolineAdapter adapter = new TwolineAdapter(this, values);  // here the difference
          setListAdapter(adapter);
      }
  ...
  }
  </code></pre>
  
  <p>So, I have added my <code>TwolineAdapter</code> class this way:</p>
  
  <pre><code>public class TwolineAdapter extends ArrayAdapter&lt;Customer&gt; {
  
      private List&lt;Customer&gt; objects;
  
      public TwolineAdapter(Context context, List&lt;Customer&gt; objects) {
          super(context, android.R.layout.simple_list_item_2, objects);
          this.objects = objects;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View view = super.getView(position, convertView, parent);
          TextView text1 = (TextView) view.findViewById(android.R.id.text1);
          TextView text2 = (TextView) view.findViewById(android.R.id.text2);
  
          text1.setText(objects.get(position).getName());
          text2.setText(objects.get(position).getInfo() 
                        + " (" + objects.get(position).getNote() + ")");
          return view;
      }
  }
  </code></pre>
  
  <p>But it did not work (apparently because of some of my errors). Notice the <code>simple_list_item_2</code> in the <code>super</code> constructor code call. When running, the code shows the error log message like:</p>
  
  <pre><code>E/ArrayAdapter(27961): You must supply a resource ID for a TextView
  </code></pre>
  
  <p>I would like to ask you where the problem is. Trying to find the reason, I have modified the <code>TwolineAdapter</code> to work the same way as the original with the <code>simple_list_item_1</code></p>
  
  <pre><code>public class TwolineAdapter extends ArrayAdapter&lt;Customer&gt; {
  
      private List&lt;Customer&gt; objects;
  
      public TwolineAdapter(Context context, List&lt;Customer&gt; objects) {
          super(context, android.R.layout.simple_list_item_1, objects);
          this.objects = objects;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          TextView view  = (TextView)super.getView(position, convertView, parent);
          view.setText(objects.get(position).getInfo());  // displaying a different info
          return view;
      }
  }
  </code></pre>
  
  <p>To be sure the overriden <code>getView</code> works, I have displayed a different part of the customer info. And it worked fine. In other words, instead of the general <code>toString</code> method, the result of my specific <code>getInfo</code> was displayed.</p>
  
  <p>Anyway, I need to use the <code>simple_list_item_2</code>. What next should I do? (My conclusion is I am doing something wrong in the constructor. Am I right? Where is the problem?)</p>