原生android,高仿大众点评商家列表;
首先欢迎大家关注我 http://weibo.com/u/2841033197
废话不多说了,上代码,效果图
适配器
class MyAdapter extends BaseAdapter {
protected final int mItemLayoutId;
List<Businesses> data = new ArrayList<Businesses>();
private Context context;
private LayoutInflater inflater;
private ImageScaleType p_w_picpathScaleType;
private DisplayImageOptions options;
public MyAdapter(List<Businesses> data, Context cxt, int itemLayoutId, ImageScaleType p_w_picpathScaleType) {
this.data = data;
this.context = cxt;
this.mItemLayoutId = itemLayoutId;
this.inflater = LayoutInflater.from(context);
this.p_w_picpathScaleType = p_w_picpathScaleType;
init();
}
/** 初始化图片缓存 options **/
private void init() {
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.thumb)
// .showImageOnFail(R.drawable.ic_error)
.cacheInMemory(true)
.cacheOnDisk(true)
.considerExifParams(true)
.p_w_picpathScaleType(p_w_picpathScaleType != null ? p_w_picpathScaleType: ImageScaleType.EXACTLY)
.delayBeforeLoading(10)
.displayer(new SimpleBitmapDisplayer())// //正常显示一张图片
.build();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data != null ? data.size() : 0;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return data != null ? data.get(position) : null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = getViewHolder(position, convertView, parent);
TextView business_id_tv = holder.getView(R.id.business_id_tv);
TextView name_tv = holder.getView(R.id.name_tv);
TextView avg_price_tv = holder.getView(R.id.avg_price_tv);
TextView regions_tv = holder.getView(R.id.regions_tv);
TextView distance_tv = holder.getView(R.id.distance_tv);
String s_photo_url = data.get(position).getS_photo_url();
String rating_s_img_url = data.get(position).getRating_img_url();
int business_id = data.get(position).getBusiness_id();
String name = data.get(position).getName();
String branch_name = data.get(position).getBranch_name();
int avg_price = data.get(position).getAvg_price();
String regions = data.get(position).getRegions();
String categories = data.get(position).getCategories();
int distance = data.get(position).getDistance();
holder.displayImages(R.id.s_photo_url_iv, s_photo_url);
holder.displayImages(R.id.star_iv, rating_s_img_url);
business_id_tv.setText("" + business_id);
name = name.substring(0, name.indexOf("("));
if (!StringUtils.isEmpty(branch_name)) {
name = name + "(" +branch_name +")";
}
name_tv.setText(name);
if (avg_price > 0) {
avg_price_tv.setText("¥" + avg_price +"/人");
}
// 过滤下数据
regions = regions.replace("\"", "").replace("[", "").replace("]", "").split(",")[1];
categories = categories.replace("\"", "").replace("[", "").replace("]", "");
regions_tv.setText(regions + " " + categories);
if (distance > 0) {
float die = distance;
DecimalFormat decimalFormat=new DecimalFormat(".0");
if(die >= 1000) {
// 大于1000 米 转化为千米展示数据
die /= 1000;
String temp_die = decimalFormat.format(die);
temp_die = temp_die.replace(".0", "");
distance_tv.setText(temp_die +"km" );
} else {
distance_tv.setText(distance +"m" );
}
}
setClick(data, holder.getConvertView(), position);
return holder.getConvertView();
}
private ViewHolder getViewHolder(int position, View convertView,
ViewGroup parent) {
return ViewHolder.get(context, convertView, parent, mItemLayoutId,
position, options);
}
private void setClick(final List<Businesses> datas, final View convertView,
final int position) {
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
int business_ids = datas.get(position).getBusiness_id();
String keywords = "";
try {
keywords = URLEncoder.encode("" + business_ids, "UTF-8");
Uri url = Uri.parse("dianping://shopinfo?id=" + keywords);
Intent intent = new Intent(Intent.ACTION_VIEW, url);
context.startActivity(intent);
} catch (Exception e) {
// 没有安装应用,默认打开HTML5站
Intent intent = new Intent(Intent.ACTION_VIEW, Uri
.parse("http://m.dianping.com/search.aspx?skey="
+ keywords));
context.startActivity(intent);
}
}
});
}
源码本人放在我的常用博客上了, 传送门
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。