package com.stone.shop.adapter;
import java.util.ArrayList;
import com.stone.shop.adapter.AsyncImageLoader.ImageCallback;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.stone.shop.R;
import com.stone.shop.model.SecondTrade;
/**
* 适配器--适配二手交易物品列表数据
*
*/
public class TradeItemListAdapter extends BaseAdapter {
private AsyncImageLoader asyncImageLoader;
ImageView iv;
private ListView mlvTradeItemAllList;
private Context mContext;
private LayoutInflater mInflater = null;
private ArrayList<SecondTrade> mTradeItemList = null; //物品列表
public TradeItemListAdapter(Context context, ArrayList<SecondTrade> tradeItemList,ListView lvTradeItemAllList) {
mlvTradeItemAllList=lvTradeItemAllList;
mContext = context;
mTradeItemList = tradeItemList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mTradeItemList.size();
}
@Override
public Object getItem(int position) {
return mTradeItemList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// 刷新列表中的数据
public void refresh(ArrayList<SecondTrade> list) {
mTradeItemList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final TradeItemHolder tradeItemHodler;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.second_trade_all_list_item, null);
tradeItemHodler = new TradeItemHolder();
tradeItemHodler.tvTradeItemName = (TextView) convertView
.findViewById(R.id.tv_trade_item_name);
tradeItemHodler.tvTradeItemType = (TextView) convertView
.findViewById(R.id.tv_trade_item_type);
tradeItemHodler.tvTradeItemPrice = (TextView) convertView
.findViewById(R.id.tv_trade_item_price);
tradeItemHodler.tvTradeItemOwner = (TextView) convertView
.findViewById(R.id.tv_trade_item_owner);
tradeItemHodler.tvTradeItemTime = (TextView) convertView
.findViewById(R.id.tv_trade_item_time);
convertView.setTag(tradeItemHodler);
} else {
tradeItemHodler = (TradeItemHolder) convertView.getTag();
}
//加载缩略图
iv = (ImageView) convertView.findViewById(R.id.img_trade_item);
String string=mTradeItemList.get(position).getPicTradeItem().getFileUrl();
Log.i("URL",string);
String url=mTradeItemList.get(position).getUrl().toString();
Log.i("URL1",url);
iv.setTag(url);
Drawable cachedImage = asyncImageLoader.loadDrawable(url, new ImageCallback() {
public void imageLoaded(Drawable imageDrawable, String imageUrl) {
ImageView imageViewByTag = (ImageView) mlvTradeItemAllList.findViewWithTag(imageUrl);
if (imageViewByTag != null) {
imageViewByTag.setImageDrawable(imageDrawable);
}
}
});
if (cachedImage == null) {
iv.setImageResource(R.drawable.ic_launcher);
}else{
iv.setImageDrawable(cachedImage);
}
tradeItemHodler.tvTradeItemName.setText(mTradeItemList.get(position).getItem());
tradeItemHodler.tvTradeItemType.setText(mTradeItemList.get(position).getType());
tradeItemHodler.tvTradeItemPrice.setText("¥ " + mTradeItemList.get(position).getPrice());
tradeItemHodler.tvTradeItemOwner.setText(mTradeItemList.get(position).getOwner());
tradeItemHodler.tvTradeItemTime.setText(mTradeItemList.get(position).getCreatedAt());
return convertView;
}
}
这是我适配器的 主要加载bmob后端上面的图片,我把图片地址保存在一列Url中。
这三张的异常代码报错,不太会看,求大神教下。
import java.util.ArrayList;
import com.stone.shop.adapter.AsyncImageLoader.ImageCallback;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.stone.shop.R;
import com.stone.shop.model.SecondTrade;
/**
* 适配器--适配二手交易物品列表数据
*
*/
public class TradeItemListAdapter extends BaseAdapter {
private AsyncImageLoader asyncImageLoader;
ImageView iv;
private ListView mlvTradeItemAllList;
private Context mContext;
private LayoutInflater mInflater = null;
private ArrayList<SecondTrade> mTradeItemList = null; //物品列表
public TradeItemListAdapter(Context context, ArrayList<SecondTrade> tradeItemList,ListView lvTradeItemAllList) {
mlvTradeItemAllList=lvTradeItemAllList;
mContext = context;
mTradeItemList = tradeItemList;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return mTradeItemList.size();
}
@Override
public Object getItem(int position) {
return mTradeItemList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
// 刷新列表中的数据
public void refresh(ArrayList<SecondTrade> list) {
mTradeItemList = list;
notifyDataSetChanged();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final TradeItemHolder tradeItemHodler;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.second_trade_all_list_item, null);
tradeItemHodler = new TradeItemHolder();
tradeItemHodler.tvTradeItemName = (TextView) convertView
.findViewById(R.id.tv_trade_item_name);
tradeItemHodler.tvTradeItemType = (TextView) convertView
.findViewById(R.id.tv_trade_item_type);
tradeItemHodler.tvTradeItemPrice = (TextView) convertView
.findViewById(R.id.tv_trade_item_price);
tradeItemHodler.tvTradeItemOwner = (TextView) convertView
.findViewById(R.id.tv_trade_item_owner);
tradeItemHodler.tvTradeItemTime = (TextView) convertView
.findViewById(R.id.tv_trade_item_time);
convertView.setTag(tradeItemHodler);
} else {
tradeItemHodler = (TradeItemHolder) convertView.getTag();
}
//加载缩略图
iv = (ImageView) convertView.findViewById(R.id.img_trade_item);
String string=mTradeItemList.get(position).getPicTradeItem().getFileUrl();
Log.i("URL",string);
String url=mTradeItemList.get(position).getUrl().toString();
Log.i("URL1",url);
iv.setTag(url);
Drawable cachedImage = asyncImageLoader.loadDrawable(url, new ImageCallback() {
public void imageLoaded(Drawable imageDrawable, String imageUrl) {
ImageView imageViewByTag = (ImageView) mlvTradeItemAllList.findViewWithTag(imageUrl);
if (imageViewByTag != null) {
imageViewByTag.setImageDrawable(imageDrawable);
}
}
});
if (cachedImage == null) {
iv.setImageResource(R.drawable.ic_launcher);
}else{
iv.setImageDrawable(cachedImage);
}
tradeItemHodler.tvTradeItemName.setText(mTradeItemList.get(position).getItem());
tradeItemHodler.tvTradeItemType.setText(mTradeItemList.get(position).getType());
tradeItemHodler.tvTradeItemPrice.setText("¥ " + mTradeItemList.get(position).getPrice());
tradeItemHodler.tvTradeItemOwner.setText(mTradeItemList.get(position).getOwner());
tradeItemHodler.tvTradeItemTime.setText(mTradeItemList.get(position).getCreatedAt());
return convertView;
}
}
这是我适配器的 主要加载bmob后端上面的图片,我把图片地址保存在一列Url中。
![](http://img.bbs.csdn.net/upload/201605/14/1463216919_230111.png)
![](http://img.bbs.csdn.net/upload/201605/14/1463216773_172995.png)
![](http://img.bbs.csdn.net/upload/201605/14/1463216947_289350.png)
这三张的异常代码报错,不太会看,求大神教下。