我有一组图像链接,我已将其存储在数组列表中,并将其传递给适配器的构造函数以供进一步处理。
我想使用Picasso在RecyclerView中显示图像。
但是当我运行我的应用程序时,Toast消息显示为“Successfully Downloaded”,但我的UI上没有显示图像视图(快照如下所示)。
以下是我的适配器
public class ImageViewAdapter extends RecyclerView.Adapter<ImageViewAdapter.MyViewHolder> {
ArrayList<MovieDetials> dataList;
Context c;
public ImageViewAdapter(ArrayList<MovieDetials> list, Context context){
dataList = list;
c = context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(c).inflate(R.layout.imagelayout,parent,false);
MyViewHolder myViewHolder = new MyViewHolder(view);
return myViewHolder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Picasso.with(c).load("https://image.tmdb.org/t/p/w500"+dataList.get(position).getPoster()).into(holder.imageView, new Callback() {
@Override
public void onSuccess() {
Toast.makeText(c, "Successfully Downloded", Toast.LENGTH_SHORT).show();
}
@Override
public void onError() {
}
});
}
@Override
public int getItemCount() {
return dataList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
ImageView imageView;
public MyViewHolder(View itemView) {
super(itemView);
imageView = (ImageView)itemView.findViewById(R.id.imageView);
}
}
}
imagelayout.xml位于
之下<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:contentDescription="An image"/>
</LinearLayout>
我正在使用网格布局管理器查看图片(下面是它的代码)
adapter = new ImageViewAdapter(data,this);
recyclerView.setLayoutManager(new GridLayoutManager(this,2));
recyclerView.setAdapter(adapter);
答案 0 :(得分:1)
将RecyclerView
身高改为match_parent
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
...
/>