我收集了图像链接的集合,这些链接已存储在数组列表中,并将其传递给适配器的构造函数以进行进一步处理。
我想使用Picasso在RecyclerView中显示图像。
但是当我运行我的应用程序时,Toast消息显示为“ Successful 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);
将RecyclerView
的高度更改为match_parent
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
...
/>