Я использовал базу данных пользовательского интерфейса Firebase для просмотра карт в моем приложении, и мой текст в списке просмотра карт не отображается только на изображении из базы данных Firebase.
это мой код:
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);
}
и Viewholder.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.java:
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;
}
и мой category_list.xml
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/category_list_cardview"
android:layout_margin="2.0dip"
android:foreground="?android:selectableItemBackground"
app:cardBackgroundColor="@android:color/white"
app:cardCornerRadius="2.0dip"
app:cardElevation="2.0dip"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:minHeight="?actionBarSize">
<ImageView
android:id="@+id/ImageView_Category"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:src="@drawable/ic_home_black_24dp"
android:layout_weight="0.005"/>
<TextView
android:id="@+id/TextView_Category"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Category"
android:textStyle="bold"
android:textColor="#000"
android:textSize="25dp"
android:gravity="center|right"
android:layout_weight="0.01"/>
</LinearLayout>
наконец скриншот моего приложения:
Скриншот
так что, пожалуйста, кто-нибудь может помочь мне узнать, в чем проблема в моем коде?