Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

android - Make FirebaseRecyclerAdapter get data under conditions and not all of them

I need to adjust somehow the FirebaseRecyclerAdapter in order to get some data from my database and not all of them. Is there any way to achieve that? My end goal is to show 10 random entries on the screen! Here is what I tried and the results:

FirebaseRecyclerAdapter<Houses, HousesViewHolder> mHousesRecyclerAdapter = new FirebaseRecyclerAdapter<Houses, HousesViewHolder>(
                Houses.class,
                R.layout.house_single,
                HousesViewHolder.class,
                mDatabaseHouses
        ) {
            @Override
            protected void populateViewHolder(HousesViewHolder viewHolder, Houses house, int position) {
                if (Integer.parseInt(house.getPrice()) > 200) {
                    viewHolder.setHouseName(house.getHouse_name());
                    viewHolder.setCity(house.getCity());
                    viewHolder.setImage(house.getMainFoto(), getApplicationContext());
                    viewHolder.setPrice(house.getPrice());
                }

            }
        };

        mRecyclerView.setAdapter(mHousesRecyclerAdapter);

enter image description here

The entries with the google logo are the houses that have price < 200 and are the houses in this example that I do not them to be appeared at all.

Single House XML:

<?xml version="1.0" encoding="utf-8"?>
<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:layout_height="wrap_content">

    <ImageView
        android:id="@+id/single_house_image"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="0dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/common_google_signin_btn_icon_dark_normal" />

    <TextView
        android:id="@+id/single_house_name_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="24dp"
        android:text="House Name"
        android:textColor="@android:color/black"
        android:textSize="18sp"
        app:layout_constraintLeft_toRightOf="@+id/single_house_image"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/single_house_location_tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="8dp"
        android:text="House Location "
        android:textSize="14sp"
        app:layout_constraintLeft_toRightOf="@+id/single_house_image"
        app:layout_constraintTop_toBottomOf="@+id/single_house_name_tv" />

    <TextView
        android:id="@+id/single_house_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="6dp"
        android:text="Price"
        android:textSize="14sp"
        app:layout_constraintLeft_toRightOf="@+id/single_house_image"
        app:layout_constraintTop_toBottomOf="@+id/single_house_location_tv" />
</android.support.constraint.ConstraintLayout>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...