package com.example.xiangmuexml;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class MyAdapter extends BaseAdapter{
private Context context;
private List<Bean1> list;
public MyAdapter(Context context, List<Bean1> list) {
super();
this.context = context;
this.list = list;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewholder;
if(convertView!=null){
viewholder=(ViewHolder) convertView.getTag();
}
else{
convertView=LayoutInflater.from(context).inflate(R.layout.activity_main_lv,null);
viewholder=new ViewHolder();
viewholder.title=(TextView)convertView.findViewById(R.id.title);
viewholder.body=(TextView)convertView.findViewById(R.id.body);
viewholder.author=(TextView)convertView.findViewById(R.id.author);
viewholder.pubDate=(TextView)convertView.findViewById(R.id.pubDate);
convertView.setTag(viewholder);
}
viewholder.title.setText(list.get(position).getTitle());
viewholder.body.setText(list.get(position).getBody());
viewholder.author.setText(list.get(position).getAuthor());
viewholder.pubDate.setText(list.get(position).getPubDate());
return convertView;
}
class ViewHolder{
private TextView title;
private TextView body;
private TextView author;
private TextView pubDate;
}
}