“大家好,我正在用recyclerviw进行凌空抽射。但是,我花了很长时间找出一个错误。在这一部分:
viewHolder.giftPicture.setImageUrl(IMAGE_URL,mImageLoader);
我不知道为什么一直说“无法解析setImageUrl”,它可以在我的其他代码部分工作。谁能帮我?谢谢。”
public class NavigationRecyclerAdapter extends RecyclerView.Adapter<NavigationRecyclerAdapter.ViewHolder> {
private Context mContext;
private List<Gift> mGifts;
ImageLoader mImageLoader;
private static final String IMAGE_URL = "http://media2.intoday.in/indiatoday/images/stories/google-doodle-story_647_032416125016.jpg";
NavigationRecyclerAdapter(Context context, List<Gift> gifts) {
mGifts = gifts;
mContext = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.card_view, viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
Gift gift = mGifts.get(i);
viewHolder.giftTitle.setText(gift.title);
viewHolder.currentPrice.setText(gift.currentPrice);
// Get the ImageLoader through your singleton class.
mImageLoader = MySingleton.getInstance(mContext).getImageLoader();
// Set the URL of the image that should be loaded into this view, and
// specify the ImageLoader that will be used to make the request.
viewHolder.giftPicture.setImageUrl(IMAGE_URL, mImageLoader);
// viewHolder.giftPicture.setImageResource(R.drawable.userimg);
viewHolder.giftTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Context context = view.getContext();
context.startActivity(new Intent(context, AddGiftsActivity.class));`enter code here`
}
});
}
@Override
public int getItemCount() {
return mGifts.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
// private final TextView mTextView;
CardView mCardView;
TextView giftTitle;
TextView currentPrice;
ImageView giftPicture;
ViewHolder(View view) {
super(view);
mCardView = (CardView)itemView.findViewById(R.id.cv);
giftTitle = (TextView)itemView.findViewById(R.id.gift_title);
currentPrice = (TextView)itemView.findViewById(R.id.current_price);
giftPicture = (NetworkImageView)itemView.findViewById(R.id.gift_picture);
}
}
}
最佳答案
ImageView没有setImageUrl方法,您需要在调用Uri或更改时将giftPicture投射为NetworkImageView
ImageView giftPicture;
至
NetworkImageView giftPicture;
在ViewHolder中
关于java - 无法解析setImageUrl,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38202096/