/**
* 附近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;
}
}
Android自定义adapter
最新推荐文章于 2024-04-29 21:46:13 发布