提问者:小点点

在Firebase Recylerview中获取空屏幕


模型

 private String name,rating,ImageUrl,description,maxminutes,minorder,minquaninty;

    public Try_Model() {

    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRating() {
        return rating;
    }

    public void setRating(String rating) {
        this.rating = rating;
    }

    public String getImageUrl() {
        return ImageUrl;
    }

    public void setImageUrl(String imageUrl) {
        ImageUrl = imageUrl;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getMaxminutes() {
        return maxminutes;
    }

    public void setMaxminutes(String maxminutes) {
        this.maxminutes = maxminutes;
    }

    public String getMinorder() {
        return minorder;
    }

    public void setMinorder(String minorder) {
        this.minorder = minorder;
    }

    public String getMinquaninty() {
        return minquaninty;
    }

    public void setMinquaninty(String minquaninty) {
        this.minquaninty = minquaninty;
    }
}

MainActivity

    mRecycleriew =findViewById(R.id.my_recycler_view);
    mRecycleriew.setLayoutManager(new LinearLayoutManager(this));



    mFirebaseDatabase=FirebaseDatabase.getInstance();
    mRef=mFirebaseDatabase.getReference().child("restaurants");


}


protected void onStart() {

    super.onStart();
    FirebaseRecyclerAdapter<Try_Model,ViewHolders>firebaseRecyclerAdapter=
            new FirebaseRecyclerAdapter<Try_Model, ViewHolders>(
                    Try_Model.class,
                    R.layout.shop_name_list,
                    ViewHolders.class,
                    mRef)
            {
                @Override
                protected void populateViewHolder(ViewHolders viewHolder, Try_Model model, int position) {


                    viewHolder.setDetails(getApplicationContext(),model.getName(),model.getDescription(),model.getImageUrl(),model.getMaxminutes(),model.getMinorder(),model.getMinquaninty(),model.getRating());

                }
            };
           mRecycleriew.setAdapter(firebaseRecyclerAdapter);
}

观众

 View mView;

public ViewHolders(View itemView) {

    super(itemView);
    mView=itemView;
}
String name,rating,ImageUrl,description,maxminutes,minorder,minquaninty;
public  void setDetails(Context ctx, String modelName, String name, String description, String ImageUrl, String maxminutes, String minorder, String minquaninty){

    TextView mName=mView.findViewById(R.id.shopTitle);
    TextView mRating=mView.findViewById(R.id.shoprating);
    TextView mDescription=mView.findViewById(R.id.shopdescrpt);
    TextView mMinorder=mView.findViewById(R.id.shopminorder);
    TextView mMaxminutes=mView.findViewById(R.id.shopmaxminutes);
    TextView mMaxQuantity=mView.findViewById(R.id.shopquantityperperson);
    ImageView mImageView = mView.findViewById(R.id.shopimageView);


    mName.setText(name);
    mDescription.setText(description);
    mMaxminutes.setText(maxminutes);
    mMinorder.setText(minorder);
    mMaxQuantity.setText(minquaninty);
    mRating.setText(rating);
    Picasso.with(mView.getContext()).load(ImageUrl).placeholder( R.drawable.progress_animation ).into(mImageView);

}

错误详情


共2个答案

匿名用户

您的rate属性的值存储为数字,但您的代码将它们声明为字符串。要修复

private String name,ImageUrl,description,maxminutes,minorder,minquaninty;
private Double rating;

public Try_Model() {

}
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public Double getRating() {
    return rating;
}

public void setRating(Double rating) {
    this.rating = rating;
}
...

匿名用户

错误就在错误日志的第一行

将java. lang.Long类型的值转换为Stringcom.google失败

尝试更改这个mRating. setText(评级);到这个mRating.setText(评级.toString());或这个mRating.setText(String.value eOf(评级));

并将模型类中rate的数据类型更改为double或Double。

让我们看看结果