Android自定义adapter

/**
 * 附近Poi Adapter类
 * Created by Lezg on 2014/5/13.
 */
public class ListViewPoiAdapter extends BaseAdapter{

    private AppContext mAppContext;
    private LayoutInflater listContainer;
    private ArrayList<MKPoiInfo> listItems;

    private int itemViewResource;

    static class ListItemView{
        public TextView name;
        public TextView address;
        public TextView distance;
    }

    public ListViewPoiAdapter(Context context,ArrayList<MKPoiInfo> data,int resource){
        this.listItems = data;
        this.itemViewResource = resource;
        this.mAppContext = AppContext.getInstance();
        this.listContainer = LayoutInflater.from(context);
    }

    public void setData(ArrayList<MKPoiInfo> data){
        this.listItems = data;
    }

    public int getCount(){
        return listItems.size();
    }

    public Object getItem(int arg0){
        return null;
    }

    public long getItemId(int arg0){
        return 0;
    }

    //ListView Item设置
    public View getView(int position, View convertView, ViewGroup parent){

        ListItemView listItemView;

        if(convertView == null){
            //获取list_item布局文件的视图
            convertView = listContainer.inflate(this.itemViewResource,null);
            listItemView = new ListItemView();
            listItemView.name = (TextView)convertView.findViewById(R.id.name);
            listItemView.address = (TextView)convertView.findViewById(R.id.addr);
            listItemView.distance = (TextView)convertView.findViewById(R.id.distance);
            convertView.setTag(listItemView);//设置控件集到convertView
        }else {
            listItemView = (ListItemView)convertView.getTag();
        }

        MKPoiInfo info = listItems.get(position);
        listItemView.name.setText(info.name);
        listItemView.address.setText(info.address);
        GeoPoint geoPoint = new GeoPoint(info.pt.getLatitudeE6(),
                info.pt.getLongitudeE6());
        double poiDistance = DistanceUtil.getDistance(mAppContext.locGeoPoint,
                geoPoint);
        String dist = StringUtils.formatDistance(poiDistance);
        listItemView.distance.setText(dist);
        return convertView;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值