SimpleNameAdapter.java (1758B)
1 /** 2 * 3 */ 4 package de.openrat.android.client.adapter; 5 6 import java.util.ArrayList; 7 import java.util.List; 8 9 import android.content.Context; 10 import android.view.LayoutInflater; 11 import android.view.View; 12 import android.view.ViewGroup; 13 import android.widget.BaseAdapter; 14 import android.widget.ImageView; 15 import android.widget.TextView; 16 import de.openrat.android.client.R; 17 18 /** 19 * @author dankert 20 * 21 */ 22 public class SimpleNameAdapter extends BaseAdapter 23 { 24 25 /** 26 * Hold onto a copy of the entire Contact List. 27 */ 28 private List<String> data = new ArrayList<String>(); 29 30 private LayoutInflater inflator; 31 32 private int imageRes; 33 34 public SimpleNameAdapter(Context context, List<String> data, int imageRes) 35 { 36 inflator = (LayoutInflater) context 37 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 38 this.data = data; 39 this.imageRes = imageRes; 40 } 41 42 public int getCount() 43 { 44 return data.size(); 45 } 46 47 public Object getItem(int position) 48 { 49 return data.get(position); 50 } 51 52 /** Use the array index as a unique id. */ 53 public long getItemId(int position) 54 { 55 return position; 56 57 } 58 59 /** 60 * @param convertView 61 * The old view to overwrite, if one is passed 62 * @returns a ContactEntryView that holds wraps around an ContactEntry 63 */ 64 public View getView(int position, View convertView, ViewGroup parent) 65 { 66 67 final View view = inflator.inflate(R.layout.listing_entry, null); 68 69 final ImageView image = (ImageView) view 70 .findViewById(R.id.listentry_image); 71 image.setImageResource(imageRes); 72 73 final TextView name = (TextView) view.findViewById(R.id.listentry_name); 74 name.setText(data.get(position)); 75 76 final TextView desc = (TextView) view 77 .findViewById(R.id.listentry_description); 78 desc.setText(""); 79 80 return view; 81 } 82 83 }