package de.wak_sh.client.backend;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.wak_sh.client.R;
import de.wak_sh.client.model.Recipient;

public class AdapterRecipients extends ArrayAdapter<Recipient> {

	private static class ViewHolder {
		public TextView textName;
		public TextView textLocation;
	}

	public AdapterRecipients(Context context, List<Recipient> objects) {
		super(context, 0, objects);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) getContext()
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(R.layout.list_item_recipient,
					parent, false);

			ViewHolder holder = new ViewHolder();
			holder.textName = (TextView) convertView
					.findViewById(R.id.textView_name);
			holder.textLocation = (TextView) convertView
					.findViewById(R.id.textView_location);

			convertView.setTag(holder);
		}

		Recipient recipient = getItem(position);
		ViewHolder holder = (ViewHolder) convertView.getTag();

		holder.textName.setText(recipient.getName());
		if (recipient.getLocation() != null) {
			holder.textLocation.setText(recipient.getLocation());
			holder.textLocation.setVisibility(View.VISIBLE);
		} else {
			holder.textLocation.setVisibility(View.GONE);
		}

		return convertView;
	}

}

@@ -142,24 +142,66 @@
 .view.View;%0A
+import android.view.View.OnClickListener;%0A
 import andro
@@ -251,24 +251,57 @@
 rayAdapter;%0A
+import android.widget.ImageView;%0A
 import andro
@@ -550,16 +550,42 @@
 cation;%0A
+%09%09public ImageView image;%0A
 %09%7D%0A%0A%09pub
@@ -716,16 +716,22 @@
 getView(
+final 
 int posi
@@ -1221,16 +1221,84 @@
 cation);
+%0A%09%09%09holder.image = (ImageView) convertView.findViewById(R.id.image);
 %0A%0A%09%09%09con
@@ -1329,16 +1329,22 @@
 %0A%09%09%7D%0A%0A%09%09
+final 
 Recipien
@@ -1697,16 +1697,155 @@
 );%0A%09%09%7D%0A%0A
+%09%09holder.image.setOnClickListener(new OnClickListener() %7B%0A%09%09%09@Override%0A%09%09%09public void onClick(View v) %7B%0A%09%09%09%09remove(recipient);%0A%09%09%09%7D%0A%09%09%7D);%0A%0A
 %09%09return
@@ -1861,11 +1861,10 @@
 iew;%0A%09%7D%0A
-%0A
 %7D%0A

Add delete image button