1

Добрый день(Вечер/ночь), у меня есть одна проблемка. Вообщем, картинки и текст в категории из Firebase загружаются только после выключения и включения экрана. Вот мой код из CategoryFragment:

package com.example.home.onlinequiz;

import android.support.v4.app.Fragment;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.Toast;

import com.example.home.onlinequiz.Interface.ItemClickListener;
import com.example.home.onlinequiz.Model.Category;
import com.example.home.onlinequiz.VievHolder.CategoryVievHolder;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;


public class CategoryFragment extends Fragment {

    View myFragment;

    RecyclerView listCategory;
    RecyclerView.LayoutManager layoutManager;
    FirebaseRecyclerAdapter <Category,CategoryVievHolder> adapter;

    FirebaseDatabase database;

    DatabaseReference categories;

    public static CategoryFragment newInstance() {
        CategoryFragment categoryFragment = new CategoryFragment();
        return categoryFragment;
    }





    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        database = FirebaseDatabase.getInstance();
        categories = database.getReference("Category");


    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        myFragment = inflater.inflate(R.layout.fragment_category,container,false);
        listCategory = (RecyclerView)myFragment.findViewById(R.id.listCategory);
        listCategory.setHasFixedSize(true);
        layoutManager = new LinearLayoutManager(container.getContext());
        listCategory.setLayoutManager(layoutManager);
        loadCategories();
        return myFragment;
    }

    private void loadCategories() {
        adapter = new FirebaseRecyclerAdapter<Category,CategoryVievHolder>(
                Category.class,
                R.layout.category_layout,
                CategoryVievHolder.class,
                categories
        ) {
            @Override
            protected void populateViewHolder(CategoryVievHolder viewHolder, final Category model, int position) {
                viewHolder.category_name.setText(model.getName());
                Picasso.with(getActivity())
                        .load(model.getImage())
                        .into(viewHolder.category_image);

                viewHolder.setItemClickListener(new ItemClickListener() {
                    @Override
                    public void onClick(View view, int position, boolean isLongClick) {
                        Toast.makeText(getActivity(), String.format("%s|%s",adapter.getRef(position).getKey(),model.getName()), Toast.LENGTH_SHORT).show();
                    }
                });

            }
        };
        adapter.notifyDataSetChanged();
        listCategory.setAdapter(adapter);
    }
    private void Categories() {
    }
}
Просьба помочь, заранее спасибо.
2
  • 1
    Окей, спасибо за ответы, а то думал что вообще не кто не ответит. Буду ждать ответа завтра, надеюсь дождусь. 15 апр 2018 в 17:26
  • А как это сделать? А то я плохо понял, можете по подробнее пожалуйста? 16 апр 2018 в 12:29

1 ответ 1

1

Уберите следующую строчку:

listCategory.setHasFixedSize(true);
1
  • Спасибо! Помогло! 16 апр 2018 в 17:14

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.