RecyclerView не прокручивает FirebaseUI - PullRequest
0 голосов
/ 22 октября 2018

Я следовал за FirebaseRecyclerViewTutorial-master на github, который доказал свою полезность, но моя проблема в том, что я не могу прокрутить, я заполнил его достаточным количеством данных для прокрутки.Мой код ниже

    public class ApartmentListActivity extends AppCompatActivity {
    RecyclerView mApartmentList;
    DatabaseReference mRef;
    private FirebaseRecyclerAdapter<ApartmentList, 
    ApartmentListActivity.ApartmentListViewHolder> mApartmentListAdapter;
    android.support.v7.widget.Toolbar toolbar;

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

        toolbar=findViewById(R.id.apartmentMenuToolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

        mRef = FirebaseDatabase.getInstance().getReference().child("apartment");
        mRef.keepSynced(true);

        mApartmentList = (RecyclerView) findViewById(R.id.apartmentMenuRecyclerView);
        mApartmentList.hasNestedScrollingParent();
        DatabaseReference apartmentRef = FirebaseDatabase.getInstance().getReference().child("apartment");
        Query listQuery = apartmentRef.orderByKey();

        mApartmentList.hasFixedSize();
        mApartmentList.setLayoutManager(new LinearLayoutManager(this));

        FirebaseRecyclerOptions apartmentListOptions = new FirebaseRecyclerOptions.Builder<ApartmentList>().setQuery(listQuery, ApartmentList.class).build();

        mApartmentListAdapter = new FirebaseRecyclerAdapter<ApartmentList, ApartmentListActivity.ApartmentListViewHolder>(apartmentListOptions) {
            @Override
            protected void onBindViewHolder (ApartmentListActivity.ApartmentListViewHolder holder, final int position, final ApartmentList model) {

                    holder.setItemThumbnail(getBaseContext(), model.getImage());
                    holder.setTitle(model.getTitle());
                    holder.setBathroomNumber(model.getBathroomNumber());
                    holder.setBedroomNumber(model.getBedroomNumber());
                    holder.setGarageNumber(model.getGarageNumber());
                    holder.setCurrentDate(model.getCurrentDate());
                    holder.setPricing(model.getPricing());
                    holder.setLocation(model.getLocation());
                    holder.setDesc(model.getDesc());
                    holder.setItemThumbnail(getApplicationContext(), model.getImage());
                    //2.    carrying view to next page
                    holder.mView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            final String titleIPE = model.getTitle();
                            final String pricingIPE = model.getPricing();
                            final String dateOfPublishingIPE = model.getCurrentDate();
                            final long bathroomNumberIPE = model.getBathroomNumber();
                            final long bedroomNumberIPE = model.getBedroomNumber();
                            final long garageNumberIPE = model.getGarageNumber();
                            final String locationIPE = model.getLocation();
                            final String descriptionIPE = model.getDesc();

                            Intent toMoreDetails = new Intent(getApplicationContext(), ApartmentMoreDetailsActivity.class);
                            toMoreDetails.putExtra("apartmentTitle", titleIPE);
                            toMoreDetails.putExtra("apartmentPricing", pricingIPE);
                            toMoreDetails.putExtra("apartmentCurrentDate", dateOfPublishingIPE);
                            toMoreDetails.putExtra("apartmentBathroomNumber", bathroomNumberIPE);
                            toMoreDetails.putExtra("apartmentBedroomNumber", bedroomNumberIPE);
                            toMoreDetails.putExtra("apartmentGarageNumber", garageNumberIPE);
                            toMoreDetails.putExtra("apartmentLocation", locationIPE);
                            toMoreDetails.putExtra("apartmentDesc", descriptionIPE);
                            toMoreDetails.putExtra("thumbnailImage", model.getImage().toString());
                            startActivity(toMoreDetails);
                        }
                    });
                }

            @Override
            public ApartmentListActivity.ApartmentListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

                View view = LayoutInflater.from(parent.getContext())
                        .inflate(R.layout.item_apartment, parent, false);

                return new ApartmentListActivity.ApartmentListViewHolder(view);
            }
        };

        mApartmentList.setAdapter(mApartmentListAdapter);

    }

    //search data
    private void firebaseSearch(String searchText){
        Query firebseSearchQuery= mRef.orderByChild("title").startAt(searchText)
                .endAt(searchText+ "\uf0ff)");

    }

    @Override
    protected void onStart() {
        super.onStart();
        mApartmentListAdapter.startListening();
    }

    @Override
    protected void onStop() {
        super.onStop();
        mApartmentListAdapter.stopListening();
    }

    public static class ApartmentListViewHolder extends  RecyclerView.ViewHolder{
        View mView;
        public ApartmentListViewHolder(View itemView){
            super(itemView);
            mView = itemView;
        }

        //views and their data configuration
        public void setItemThumbnail(Context ctx, String image){
            ImageView itemThumbnail=mView.findViewById(R.id.apartmentThumbnailImageView);

            //picasso's 2.7 doesnt have the with() method so I downgraded my gradle dependency to support cetext
            Picasso.with(ctx).load(image).into(itemThumbnail);
        }

        public void setTitle(String title){
            TextView titleTv= mView.findViewById(R.id.apartmentTitleTextview);
            titleTv.setText(String.valueOf(title));
        }

        public void setBathroomNumber (Long bathroomNumber){
            TextView bathroomNumberTv= mView.findViewById(R.id.apartmentBathroomNumberTextView);
            bathroomNumberTv.setText(String.valueOf(bathroomNumber));
        }

        public void setBedroomNumber (Long bedroomNumber){
            TextView bedroomNumberTv= mView.findViewById(R.id.apartmentBedroomNumberTextView);
            bedroomNumberTv.setText(String.valueOf(bedroomNumber));
        }

        public void setGarageNumber (Long garageNumber){
            TextView garageNumberTv= mView.findViewById(R.id.apartmentGarageNumberTextView);
            garageNumberTv.setText(String.valueOf(garageNumber));
        }

        public void setCurrentDate (String currentDate){
            TextView currentDateTv= mView.findViewById(R.id.apartmentCurrentDateTextview);
            currentDateTv.setText(currentDate);
        }

        public void setPricing (String pricing){
            TextView pricingTextView = mView.findViewById(R.id.apartmentPricingTextView);
            pricingTextView.setText(pricing);
        }

        public void setLocation(String location)
        {
            TextView locationTextView = mView.findViewById(R.id.apartmentLocationTextView);
            locationTextView.setText(location);
            assert locationTextView !=null;
        }

        public void setDesc(String desc) {
            TextView descriptionTextView = mView.findViewById(R.id.apartmentDescriptionTextView);
            descriptionTextView.setText(desc);
            assert descriptionTextView !=null;
        }

    }

мой xml-код, который в основном состоит из менеджера компоновки, панели инструментов и реселлера. View

<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="match_parent"
tools:context=".activity.ApartmentListActivity">

<android.support.v7.widget.Toolbar
    android:id="@+id/apartmentMenuToolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryDark"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:navigationIcon="?homeAsUpIndicator"
    app:subtitle="Get all you need with no extra charge!"
    app:subtitleTextColor="#ffffff"
    app:title="Apartment"
    app:titleTextColor="#ffffff" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/apartmentMenuRecyclerView"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:background="#ffffff"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/apartmentMenuToolbar"
    app:layout_constraintVertical_bias="0.0" />

</android.support.constraint.ConstraintLayout>

Текущий вывод кода спасибозаранее за вашу помощь.

Ответы [ 2 ]

0 голосов
/ 22 октября 2018

Измените свой макет Recyclerview на этот

<android.support.v7.widget.RecyclerView
android:id="@+id/apartmentMenuRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/apartmentMenuToolbar"
app:layout_constraintVertical_bias="0.0" />

Я советую вам использовать CoordinatorLayout в качестве корневого макета для несложных макетов.

В CoordinatorLayout это будет выглядеть так

<android.support.design.widget.CoordinatorLayout 
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="match_parent"
tools:context=".activity.ApartmentListActivity">

<android.support.v7.widget.Toolbar
android:id="@+id/apartmentMenuToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:navigationIcon="?homeAsUpIndicator"
app:subtitle="Get all you need with no extra charge!"
app:subtitleTextColor="#ffffff"
app:title="Apartment"
app:titleTextColor="#ffffff" />

<android.support.v7.widget.RecyclerView
android:id="@+id/apartmentMenuRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff" />

</android.support.design.widget.CoordinatorLayout>
0 голосов
/ 22 октября 2018
 android:scrollbars="vertical"

Добавьте этот атрибут в свой recyclerView в формате xml для поддержки прокрутки

...