作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个问题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/
我是一名优秀的程序员,十分优秀!