<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
package gt.gt;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class MyAdapter extends ArrayAdapter {
LayoutInflater mInflater;
private RSSFeed feed=null;
public final String RSS_URL="http://feed.feedsky.com/yeeyan_top";
List <Map<String,Object>> data;
public List<Map<String, Object>> getData() {
return data;
}
public void setData(List<Map<String, Object>> data) {
this.data = data;
}
public MyAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
feed=getFeed(RSS_URL);
// data=feed.getAllItemsForListView();
mInflater =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
private RSSFeed getFeed(String urlString)
{
try{
URL url=new URL(urlString);
SAXParserFactory factory=SAXParserFactory.newInstance();
SAXParser parser=factory.newSAXParser();
XMLReader xmlreader=parser.getXMLReader();
RSSHandler rssHandler=new RSSHandler();
xmlreader.setContentHandler(rssHandler);
InputSource is = new InputSource(url.openStream());
xmlreader.parse(is);
return rssHandler.getFeed();
}
catch(Exception ee)
{
return null;
}
}
@Override
public int getCount() {
return data.size();
}
static class ViewHolder{
TextView text1;
TextView text2;
//ImageView icon;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView==null){
convertView=mInflater.inflate(R.layout.row,null);
holder= new ViewHolder();
holder.text1=(TextView)convertView.findViewById(R.id.textView1);
holder.text2=(TextView)convertView.findViewById(R.id.textView2);
convertView.setTag(holder);
}
else{
holder=(ViewHolder)convertView.getTag();
}
holder.text1.setText((String)(data.get(position).get(RSSItem.TITLE)));
//holder.text2.setText(array.get(position).toString());
holder.text2.setText((String)(data.get(position).get(RSSItem.PUBDATE)));
return convertView;
//return super.getView(position, convertView, parent);
}
}