解析されたxmlデータをカスタムリストビューで表示しようとしていますが、画面が空になっているようです。クラスオブジェクトにxmlデータを追加し、カスタムリストビューに表示しようとしています。しかし、私のクラス変数は値を割り当てていません
リストmyNews=new ArrayList();
try{
URL url = new URL("http://timesofindia.feedsportal.com/c/33039/f/533916/index.rss");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(getInputStream(url), "UTF_8");
boolean insideItem = false;
int eventType = xpp.getEventType();
while(eventType != XmlPullParser.END_DOCUMENT){
if(eventType == XmlPullParser.START_TAG){
if(xpp.getName().equalsIgnoreCase("item")){
insideItem = true;
}
else if(xpp.getName().equalsIgnoreCase("title")){
if(insideItem){
headLines = xpp.nextText().toString();
}
}
else if(xpp.getName().equalsIgnoreCase("link")){
if(insideItem){
links.add(xpp.nextText());
}
}
else if(xpp.getName().equalsIgnoreCase("pubDate")){
if(insideItem){
date = xpp.nextText().toString();
}
}
}
else if(eventType == XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){
insideItem = false;
}
myNews.add(new News(headLines, date));
eventType = xpp.next();
}
}
catch (Exception e) {
Log.d("Exception" , e.toString());
}
LazyAdapter adapter = new LazyAdapter(this, myNews);
setListAdapter(adapter);
ListView listView = getListView();
listView.setTextFilterEnabled(true);
これが私のLazyAdapterコードです...
パブリッククラスLazyAdapterはBaseAdapterを拡張します{
Activity activity;
private List<News> myNews;
public LazyAdapter(Activity a, List<News> myNews) {
this.activity = a;
this.myNews = myNews;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
News news = myNews.get(position);
View v = convertView;
if(v == null){
LayoutInflater inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.list, null);
}
TextView heading = (TextView)v.findViewById(R.id.textView1);
heading.setText(news.getTitle());
TextView pubDate = (TextView)v.findViewById(R.id.textView2);
pubDate.setText(news.getPubDate());
heading.setText(news.getTitle());
pubDate.setText(news.getPubDate());
return v;
}
@Override
public int getCount() {
return myNews.size();
}
@Override
public Object getItem(int position) {
return myNews.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}