我想展示Firebase的一系列ImageView

时间:2018-09-28 00:45:27

标签: android firebase android-recyclerview

我想使用RecyclerView从Firebase展示一系列ImageView

将model.getImage2(),model.getImage3(),model.getImage4()放入setDetails()时出现错误,有一种方法可以同时放置4张图像

这是我来自“活动”的代码

 public void onStart() {
    super.onStart();
    FirebaseRecyclerAdapter<Model, ViewHolder> firebaseRecyclerAdapter =
            new FirebaseRecyclerAdapter<Model, ViewHolder>(
                    Model.class,
                    R.layout.resourcerow,
                    ViewHolder.class,
                    mRef
            ) {
                @Override
                protected void populateViewHolder(ViewHolder viewHolder, Model model, int position) {

                    viewHolder.setDetails(getApplicationContext(),model.getTitle(),model.getDescription(),model.getImage(),model.getImage2(),model.getImage3(),model.getImage4());

                }
            };
    mRecyclerView.setAdapter(firebaseRecyclerAdapter);
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle("Undercuts");


    vLinearLayoutManager = new LinearLayoutManager(this);

    setContentView(R.layout.activity_under_cuts);

    mRecyclerView =findViewById(R.id.rcyHairstyle);

    mRecyclerView.setLayoutManager(vLinearLayoutManager);

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

}

这是我CardView中的代码:

<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="250dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardBackgroundColor="#191919"
app:cardCornerRadius="5dp"
app:cardElevation="3dp"
app:contentPadding="5dp"
app:cardUseCompatPadding="true">

<LinearLayout

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">


    <com.makeramen.roundedimageview.RoundedImageView
        android:scaleType="centerCrop"
        android:id="@+id/rImageView"
        app:riv_corner_radius="8dip"
        android:layout_width="120dp"
        android:layout_height="180dp"
        android:background="@drawable/loadicon"
        />
    <com.makeramen.roundedimageview.RoundedImageView
        android:scaleType="centerCrop"
        android:id="@+id/rImageView2"
        app:riv_corner_radius="8dip"
        android:layout_width="120dp"
        android:layout_height="180dp"
        android:background="@drawable/loadicon"
        />
    <com.makeramen.roundedimageview.RoundedImageView
        android:scaleType="centerCrop"
        android:id="@+id/rImageView3"
        app:riv_corner_radius="8dip"
        android:layout_width="120dp"
        android:layout_height="180dp"
        android:background="@drawable/loadicon"
        />
    <com.makeramen.roundedimageview.RoundedImageView
        android:scaleType="centerCrop"
        android:id="@+id/rImageView4"
        app:riv_corner_radius="8dip"
        android:layout_width="120dp"
        android:layout_height="180dp"
        android:background="@drawable/loadicon"
        />

    <LinearLayout
        android:layout_marginLeft="10dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">


    <TextView
        android:layout_marginLeft="10dp"
        android:id="@+id/rTitletv"
        android:text="Title"
        android:textColor="#ffffff"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_marginLeft="10dp"
        android:id="@+id/rDescription"
        android:textColor="#ffffff"
        android:text="Description"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
  </LinearLayout>

</LinearLayout>

这是我的Recycler中的代码查看活动:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/frmHairstyle"
android:background="#000000"
android:layout_height="match_parent"
tools:context=".UnderCuts">


<android.support.v7.widget.RecyclerView
    android:id="@+id/rcyHairstyle"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />

0 个答案:

没有答案