RSSContentAdapter.java (2039B)
1 /** 2 * 3 */ 4 package de.mtbnews.android.adapter; 5 6 import org.mcsoxford.rss.RSSFeed; 7 import org.mcsoxford.rss.RSSItem; 8 9 import android.content.Context; 10 import android.text.Html; 11 import android.text.format.DateFormat; 12 import android.view.LayoutInflater; 13 import android.view.View; 14 import android.view.ViewGroup; 15 import android.widget.BaseAdapter; 16 import android.widget.TextView; 17 import de.mtbnews.android.R; 18 19 /** 20 * @author dankert 21 * 22 */ 23 public class RSSContentAdapter extends BaseAdapter 24 { 25 26 /** Remember our context so we can use it when constructing views. */ 27 private Context mContext; 28 29 /** 30 * Hold onto a copy of the entire Contact List. 31 */ 32 33 private LayoutInflater inflator; 34 35 private RSSFeed feed; 36 37 public RSSContentAdapter(Context context, RSSFeed feed) 38 { 39 mContext = context; 40 inflator = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 41 this.feed = feed; 42 } 43 44 public int getCount() 45 { 46 return feed.getItems().size(); 47 } 48 49 public Object getItem(int position) 50 { 51 return feed.getItems().get(position); 52 } 53 54 /** Use the array index as a unique id. */ 55 public long getItemId(int position) 56 { 57 return position; 58 59 } 60 61 /** 62 * @param convertView 63 * The old view to overwrite, if one is passed 64 * @returns a ContactEntryView that holds wraps around an ContactEntry 65 */ 66 public View getView(int position, View convertView, ViewGroup parent) 67 { 68 69 RSSItem e = feed.getItems().get(position); 70 71 final View view = inflator.inflate(R.layout.rss_item, null); 72 73 TextView datum = (TextView) view.findViewById(R.id.item_date); 74 datum.setText(DateFormat.getDateFormat(parent.getContext()).format(e.getPubDate()) + " " 75 + DateFormat.getTimeFormat(parent.getContext()).format(e.getPubDate())); 76 77 TextView name = (TextView) view.findViewById(R.id.item_title); 78 name.setText(e.getTitle()); 79 80 TextView desc = (TextView) view.findViewById(R.id.item_description); 81 82 if (e.getDescription() != null) 83 desc.setText(e.getDescription() + " ..."); 84 else 85 desc.setText(""); 86 87 return view; 88 } 89 90 }