gpt4 book ai didi

android - RecyclerView 适配器没有膨胀 xml 布局

转载 作者:行者123 更新时间:2023-11-30 00:31:24 25 4
gpt4 key购买 nike

我有一组图像链接,我将它们存储在一个数组列表中,并将其传递给适配器的构造函数以进行进一步处理。

我想使用 Picasso 在 RecyclerView 中显示图像。

But when I run my app the Toast message appears "Successfully Downloaded", but no image view shown on my UI(snapshot is shown below). enter image description here

下面是我的适配器

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"
...
/>

关于android - RecyclerView 适配器没有膨胀 xml 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44274206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com