我在Cardview应用中没有出现文字问题

时间:2019-04-05 00:14:24

标签: java android firebase firebase-realtime-database recycler-adapter

我使用firebase UI数据库在应用程序中进行卡片查看,并且卡片视图列表中的文本不仅仅显示firebase数据库中的图像。

这是我的代码:

'$one is 5', '$two is 4', '20' -join ' '

和Viewholder.java:

private RecyclerView mRecyclerView;
private FirebaseDatabase mFirebaseDatabase;
private DatabaseReference mRef;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    mRecyclerView = (RecyclerView) findViewById(R.id.RecycleView);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    mFirebaseDatabase = FirebaseDatabase.getInstance();
    mRef = mFirebaseDatabase.getReference("Category");


}

@Override
protected void onStart() {
    super.onStart();

    FirebaseRecyclerAdapter<Category, ViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Category, ViewHolder>
            (Category.class, R.layout.category_list, ViewHolder.class, mRef) {
        @Override
        protected void populateViewHolder(ViewHolder viewHolder, Category model, int position) {
            viewHolder.setTitle(model.getTitle());
            viewHolder.setImg(model.getImage());
        }
    };

    mRecyclerView.setAdapter(firebaseRecyclerAdapter);
}

和Category.java:

public class ViewHolder extends RecyclerView.ViewHolder {

View mView;

public ViewHolder(View itemView) {
    super(itemView);

    mView = itemView;

}

public void setImg(String image)
{

    ImageView imageCategoryView = mView.findViewById(R.id.ImageView_Category);
    Picasso.get().load(image).into(imageCategoryView);

}

public void setTitle(String title)
{
    TextView mTitleView = mView.findViewById(R.id.TextView_Category);
    mTitleView.setText(title);
}

和我的category_list.xml

public class Category {

private String title;
private String Image;

public Category()
{

}

public Category(String title_Text, String image) {
    title = title_Text;
    Image = image;
}

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    title = title;
}

public String getImage() {
    return Image;
}

public void setImage(String image) {
    Image = image;
}

最后是我的应用的屏幕截图:

this answer 因此,请任何人都可以帮助我知道我的代码中存在什么问题?

0 个答案:

没有答案