title: ListView Adapter
body: <p>I wanted to create a <code>ListView</code> adapter to display multiple data, such as <code>Username</code>, <code>Comment</code>, <code>Date</code> and <code>Rating</code> together in one row. It's like displaying comments in the forums. I have 4 arrays and each of the array stores one of these value (<code>Username</code>, <code>Comment</code>, <code>Date</code> and <code>Rating</code>). I tried using the below code to create a custom adapter for this. But I don't really know the correct way to implement this. I tried running this and it only displayed out <code>Username</code> and <code>Date</code>. I'm not sure whether this code is the correct way to implement or not.</p>
  
  <pre><code>Float f = Float.parseFloat(commentRating[position]);
  holder.cmtRating.setRating(f);
  </code></pre>
  
  <p><strong>Content.java</strong>:</p>
  
  <pre><code>list = (ListView) findViewById(R.id.commentlist);
  adapter=new CommentAdapter(ContentScreen.this);
  list.setAdapter(adapter);
  
  public class CommentAdapter extends BaseAdapter {
  
      private Activity activity;
      private LayoutInflater inflater=null;
  
      public CommentAdapter(Activity a) {
          activity = a;
          inflater = (LayoutInflater) activity.getSystemService(
                  Context.LAYOUT_INFLATER_SERVICE);
      }
  
      public int getCount() {
          return commentText.length;
      }
  
      public Object getItem(int position) {
          return position;
      }
  
      public long getItemId(int position) {
          return position;
      }
  
      public class ViewHolder{
          public TextView cmtUser;
          public TextView cmtText;
          public RatingBar cmtRating;
          public TextView cmtTime;
          public ImageView image;
      }
  
      public View getView(int position, View convertView, ViewGroup parent) {
          View vi = convertView;
          ViewHolder holder;
          if (convertView == null) {
              vi = inflater.inflate(R.layout.comment, null);
              holder = new ViewHolder();
              holder.cmtUser = (TextView) vi.findViewById(R.id.commentby);
              holder.cmtText = (TextView) vi.findViewById(R.id.comment);
              holder.cmtRating = (RatingBar) vi.findViewById(R.id.commentrating);
              holder.cmtTime = (TextView) vi.findViewById(R.id.commentcreatedby);
              vi.setTag(holder);
          } else
              holder=(ViewHolder)vi.getTag();
  
          holder.cmtUser.setText(commentBy[position]);
          holder.cmtText.setText(commentText[position]);
          Float f = Float.parseFloat(commentRating[position]);
          holder.cmtRating.setRating(f);
          holder.cmtTime.setText(commentCreatedTime[position]);
          return vi;
      }
  }
  </code></pre>
  
  <p>Any answers and comments are appreciated.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>comment.xml</p>
  
  <p></p>
  
  <pre><code>&lt;TextView
      android:id="@+id/comment"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@+id/commentcreatedby"
      android:layout_alignParentLeft="true"
      android:layout_below="@+id/commentby"
      android:paddingLeft="5dp"
      android:paddingTop="5dp"/&gt;
  
  &lt;TextView
      android:id="@+id/commentcreatedby"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:paddingRight="5dp"
      android:paddingTop="5dp"/&gt;
  
  &lt;TextView
      android:id="@+id/commentby"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:paddingLeft="5dp"
      android:paddingTop="5dp" /&gt;
  
  &lt;RatingBar
      android:id="@+id/commentrating"
      style="?android:attr/ratingBarStyleSmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@+id/comment"
      android:layout_alignParentRight="true"
      android:layout_marginRight="16dp" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>content.xml</p>
  
  <p></p>
  
  <pre><code>&lt;include
      android:id="@+id/top_header"
      android:layout_width="match_parent"
      layout="@layout/header" /&gt;
  
  &lt;TextView
      android:id="@+id/content_desc"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_below="@+id/top_header"
      android:padding="10dip"/&gt;
  
  &lt;ImageView
      android:id="@+id/content_image"
      android:layout_width="fill_parent"
      android:layout_height="160dip"
      android:layout_alignParentLeft="true"
      android:layout_below="@+id/content_desc"
      android:padding="10dip" /&gt;
  
  
  &lt;ListView
      android:id="@+id/commentlist"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_below="@+id/content_price" &gt;
  
  &lt;/ListView&gt;
  
  &lt;TextView
      android:id="@+id/content_price"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_below="@+id/content_image"
      android:layout_marginLeft="29dp"
      android:layout_marginTop="44dp"
      android:padding="10dip"
      android:textSize="20dp" /&gt;
  
  &lt;Button
      android:id="@+id/content_subscribe"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_above="@+id/commentlist"
      android:layout_alignParentRight="true"
      android:layout_marginRight="38dp"
      android:padding="20dip"
      android:paddingRight="20dip"
      android:text="Subscribe" /&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>The rating is working as well. But it stacked together with the date. As for the comment, I still cant get it working.</p>
  
  <p><strong>UPDATE (SOLVED)</strong>
  Apparently it's my comment.xml arrangement got some sort of issue. Once I re-arrange it, the comment appear and everything works fine. Thank you for everyone's time. </p>