title: Android - Executing a custom listview in a custom dialog properly
body: <p>I have an application where I would want to display a custom list view consisting of two textViews inside a custom dialog box in android. So far, I'm having a difficult time figuring out how to connect the two and generate the contents of the dialog box. </p>
  
  <p>I tried to follow custom listView tutorials with the hopes of just setting the dialog adapter to it but to no avail. </p>
  
  <p>So far, this is what I have so far:</p>
  
  <p>This is list_row_dialog.xml, the layout for the row containing two textviews:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:minHeight="50dp"
      android:orientation="horizontal"
      android:padding="5dip" &gt;
  
  &lt;TextView
      android:id="@+id/unit"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textStyle="bold"
      android:typeface="sans" /&gt;
  
  &lt;TextView
      android:id="@+id/quantity"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentRight="true"
      android:layout_alignParentTop="true"
      android:textColor="#343434"
      android:textSize="12sp" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And here is the dialog_main.xml file, the layout file that I want the dialog box to use, it's basically a listView.</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/custom_list"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:dividerHeight="1dp" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And here's CustomListAdapterDialog.java, I'm not sure if I even need to use this to display data on the dialog box:</p>
  
  <pre><code>public class CustomListAdapterDialog extends BaseAdapter {
  
  private ArrayList&lt;ItemClass&gt; listData;
  
  private LayoutInflater layoutInflater;
  
  public CustomListAdapterDialog(Context context, ArrayList&lt;ItemClass&gt; listData) {
      this.listData = listData;
      layoutInflater = LayoutInflater.from(context);
  }
  
  @Override
  public int getCount() {
      return listData.size();
  }
  
  @Override
  public Object getItem(int position) {
      return listData.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return position;
  }
  
  public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
      if (convertView == null) {
          convertView = layoutInflater.inflate(R.layout.list_row_dialog, null);
          holder = new ViewHolder();
          holder.unitView = (TextView) convertView.findViewById(R.id.unit);
          holder.quantityView = (TextView) convertView.findViewById(R.id.quantity);
          convertView.setTag(holder);
      } else {
          holder = (ViewHolder) convertView.getTag();
      }
  
      holder.unitView.setText(listData.get(position).getVariant().toString());
      holder.quantityView.setText(listData.get(position).getUnit().toString());
  
      return convertView;
  }
  
  static class ViewHolder {
      TextView unitView;
      TextView quantityView;
  }
  
  }
  </code></pre>
  
  <p>Initially, I tried this code to display the dialog box:</p>
  
  <pre><code>private void showDialog(){
      final Dialog dialog = new Dialog(this);
      dialog.setContentView(R.layout.dialog_main);
  
  
      dialog.show();
  }
  </code></pre>
  
  <p>But it only shows, one blank row, it is very clear that I am not populating it properly. </p>
  
  <p>Any ideas anyone? Also, I can populate the dialog boxes in the <code>showDialog()</code> function since I also have the data I want to populate with in the same java class.</p>