安卓开发app里一些代码不懂 能不能尽可能地注释!每一行写清楚一些!求大神
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
final Shop shop= mData.get(position);
if (convertView == null) {
holder=new ViewHolder();
convertView = mInflater.inflate(R.layout.shop_list, null);
holder.shop_ll = (LinearLayout)convertView.findViewById(R.id.shop_ll);
holder.img = (ImageView)convertView.findViewById(R.id.img);
holder.name_tv = (TextView)convertView.findViewById(R.id.name_tv);
holder.score_tv = (TextView)convertView.findViewById(R.id.score_tv);
convertView.setTag(holder);
}else {
holder = (ViewHolder)convertView.getTag();
}
holder.img.setBackgroundResource((Integer) shop.pic);
holder.name_tv.setText((String) shop.name);
holder.score_tv.setText("评分:"+shop.score);
holder.shop_ll.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//进入指定店铺
Intent intent = new Intent();
//指定店铺名
intent.putExtra("name", shop.name);
intent.setClass(getActivity(),
ShopActivity.class);
startActivity(intent);
}
});
return convertView;
}
cuni
浏览 1568回答 2
打开App,查看更多内容