package com.brogrammers.agora;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CommentAdapter extends BaseAdapter {
	private Answer answer;
	private LayoutInflater inflater;

	CommentAdapter(Answer a){
		this.answer = a;
		this.inflater = (LayoutInflater)Agora.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);	
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return answer.countComments();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return answer.getComments().get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return (Long) null;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView == null){
			convertView = inflater.inflate(R.layout.comment_object, null);
		}
		
		//inflate each listview item with "comment_object"
		Comment comment = (Comment)getItem(position);
		//set text on each TextView			
		((TextView)convertView.findViewById(R.id.cBody)).setText(comment.getBody());
		((TextView)convertView.findViewById(R.id.cAuthourDate)).setText(comment.getDate().toString());
		
		return convertView;
	}

}

@@ -399,16 +399,46 @@
 later;%0D%0A
+%09private Question question;%0D%0A%09
 %0D%0A%09Comme
@@ -479,16 +479,41 @@
 r = a;%0D%0A
+%09%09this.question = null;%0D%0A
 %09%09this.i
@@ -609,24 +609,218 @@
 VICE);%09%0D%0A%09%7D%0D
+%0A%09%0D%0A%09CommentAdapter(Question q)%7B%0D%0A%09%09this.answer = null;%0D%0A%09%09this.question = null;%0D%0A%09%09this.inflater = (LayoutInflater)Agora.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);%09%0D%0A%09%7D%0D%0A%09%0D
 %0A%0D%0A%09@Overrid
@@ -878,32 +878,58 @@
 ed method stub%0D%0A
+%09%09if(question == null)%7B%0D%0A%09
 %09%09return answer.
@@ -942,24 +942,78 @@
 omments();%0D%0A
+%09%09%7D else %7B%0D%0A%09%09%09return question.countComments();%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A%0D%0A%09@Over
@@ -1088,32 +1088,58 @@
 ed method stub%0D%0A
+%09%09if(question == null)%7B%0D%0A%09
 %09%09return answer.
@@ -1168,16 +1168,80 @@
 tion);%0D%0A
+%09%09%7D else %7B%0D%0A%09%09%09return answer.getComments().get(position);%0D%0A%09%09%7D%0D%0A
 %09%7D%0D%0A%0D%0A%09@

Update to CommentAdapter change adapter to reflect the fact that questions can also have comments