gpt4 book ai didi

java - 回收器 View : No adapter attached; skipping layout (no shw Slider and photos Picasso and Sliderbanner

转载 作者:行者123 更新时间:2023-12-02 05:42:52 27 4
gpt4 key购买 nike

我有这个问题RecyclerView:没有连接适配器;跳过布局

java、安卓

我的 fragment

public class HomeFragment extends Fragment implements ILookbookLoadListener, IBannerLoadListener {

private Unbinder unbinder;

@BindView(R.id.layout_user_information)
LinearLayout layout_user_information;
@BindView(R.id.txt_user_name)
TextView txt_user_name;
@BindView(R.id.banner_slider)
Slider banner_slider;
@BindView(R.id.recycler_look_book)
RecyclerView recycler_look_book;
//FireStore

CollectionReference bannerRef,lookbookRef;

//Interface
IBannerLoadListener iBannerLoadListener;
ILookbookLoadListener iLookbookLoadListener;



public HomeFragment() {

bannerRef = FirebaseFirestore.getInstance().collection("Banner");
lookbookRef = FirebaseFirestore.getInstance().collection("Lookbook");
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_home,container,false);
unbinder = ButterKnife.bind(this,view);

//init
Slider.init(new PicassoImageLoadingService());
iBannerLoadListener =this;
iLookbookLoadListener = this;

//check if loged
if (AccountKit.getCurrentAccessToken() != null)
{
setUserInformation();
loadBanner();
loadLookBook();
}
return view;
}

private void loadLookBook() {
lookbookRef.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
List<Banner> lookbooks = new ArrayList<>();
if (task.isSuccessful())
{
for (QueryDocumentSnapshot bannerSnapShot:task.getResult())
{
Banner banner = bannerSnapShot.toObject(Banner.class);
lookbooks.add(banner);
}
iLookbookLoadListener.onLookbookLoadSuccess(lookbooks);
}

}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
iLookbookLoadListener.onLookbookLoadFailed(e.getMessage());

}
});

}

private void loadBanner() {
bannerRef.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
List<Banner> banners = new ArrayList<>();
if (task.isSuccessful())
{
for (QueryDocumentSnapshot bannerSnapShot:task.getResult())
{
Banner banner = bannerSnapShot.toObject(Banner.class);
banners.add(banner);
}
iBannerLoadListener.onBannerLoadSuccess(banners);
}

}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
iBannerLoadListener.onBannerLoadFailed(e.getMessage());

}
});
}

private void setUserInformation() {
layout_user_information.setVisibility(View.VISIBLE);
txt_user_name.setText(Common.currentUser.getName());
}

@Override
public void onLookbookLoadSuccess(List<Banner> banners) {
recycler_look_book.setHasFixedSize(true);
recycler_look_book.setLayoutManager(new LinearLayoutManager(getActivity()));
recycler_look_book.setAdapter(new LookbookAdapter(getActivity(),banners));

}

@Override
public void onLookbookLoadFailed(String message) {
Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();

}

@Override
public void onBannerLoadSuccess(List<Banner> banners) {
banner_slider.setAdapter(new HomeSliderAdapter(banners));

}

@Override
public void onBannerLoadFailed(String message) {
Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();

}

}

适配器

public class LookbookAdapter extends RecyclerView.Adapter<LookbookAdapter.MyviewHolder> {
Context context;
List<Banner> lookbook;

public LookbookAdapter(Context context, List<Banner> lookbook) {
this.context = context;
this.lookbook = lookbook;
}

@NonNull
@Override
public MyviewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(context)
.inflate(R.layout.layout_look_book,viewGroup,false);
return new MyviewHolder(itemView);
}

@Override
public void onBindViewHolder(@NonNull MyviewHolder myviewHolder, int i) {
Picasso.get().load(lookbook.get(i).getImage()).into(myviewHolder.imageView);

}

@Override
public int getItemCount() {
return lookbook.size();
}

public class MyviewHolder extends RecyclerView.ViewHolder{
ImageView imageView;
public MyviewHolder(@NonNull View itemView) {
super(itemView);

imageView = (ImageView)itemView.findViewById(R.id.image_look_book);
}
}

}

slider 适配器

public class HomeSliderAdapter extends SliderAdapter {
List<Banner> bannerList;

public HomeSliderAdapter(List<Banner> bannerList) {
this.bannerList = bannerList;
}

@Override
public int getItemCount() {
return bannerList.size();
}

@Override
public void onBindImageSlide(int position, ImageSlideViewHolder imageSlideViewHolder) {
imageSlideViewHolder.bindImageSlide(bannerList.get(position).getImage());

}

}

最佳答案

@Override
public void onLookbookLoadSuccess(List<Banner> banners) {
recycler_look_book.setHasFixedSize(true);
recycler_look_book.setLayoutManager(new LinearLayoutManager(getActivity()));
recycler_look_book.setAdapter(new LookbookAdapter(getActivity(),banners));

}

只有当响应成功时才会连接您的适配器,如上所示。因此,如果您的响应不成功,您的适配器将不会附加到 recyclerView。其实这是一个警告。所以你应该记录你的回应。

关于java - 回收器 View : No adapter attached; skipping layout (no shw Slider and photos Picasso and Sliderbanner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56122392/

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