How to save the size of my recyclerview

Asked

Viewed 108 times

0

The size of my recyclerview and second shape setado mDatabase.limitToFirst(valor1*valor2)... valor1 = 1 * valor= 4 = 4

When I roll the recyclerview till the end call EndlessRecyclerViewScrollListener who calls the accountant valor1++ valor1 = 2 * valor= 4 = 8 what happens is that every roll to the end increases 4 by 4.

the problem is when I step into the next activity(open the content), When I come back I want to continue with the same size... I don’t know how to save this result and retrieve it... I tried to savedInstance more I never used before so it didn’t work out... putExtra does not give since the click is done in the activity of recyclerview... finally I thank to those who help!

LoadData();

}
private void LoadData() {

    mDatabase.limitToFirst(valor1*valor2)
            .startAt(valor2)
            .orderByChild("number").addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            questionList.clear();
            if(!dataSnapshot .hasChildren()){
                //currentPage--;
            }
            for (DataSnapshot data : dataSnapshot.getChildren()) {
                Blog blog = data.getValue(Blog.class);
                questionList.add(blog);
                mAdapter.notifyDataSetChanged();
                String posicao = counter = getIntent().getExtras().getString("position");
                mProgress.setVisibility(View.GONE);
                if(Load == false){
                    recyclerView.smoothScrollToPosition(Integer.parseInt(posicao));
                    Load = true;
                }else{
                }

                Handler handle = new Handler();
                handle.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mRela.setVisibility(View.GONE);
                    }
                }, 1000);

            }

        }


        @Override public void onCancelled(DatabaseError databaseError) {

        }
    });

    if(Load == false){
        recyclerView.post(new Runnable() {
            final String posicao = counter = getIntent().getExtras().getString("position");
            @Override
            public void run() {
                // Call smooth scroll
                Log.i("TESTEEEE",posicao);
                recyclerView.smoothScrollToPosition(Integer.parseInt(posicao));
                Load = true;
            }
        });}else{

    }}
@Override public void onStart() {
    recyclerView.addOnScrollListener(new EndlessRecyclerViewScrollListener(mLayoutManager) {
        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            mProgress.setVisibility(View.VISIBLE);
            Handler handle = new Handler();
            handle.postDelayed(new Runnable() {
                @Override
                public void run() {
                    valor1++;
                    LoadData();}
            },2000);

        }
    });
    super.onStart();
}

   

   public class RecyclerViewBlog extends 
   RecyclerView.Adapter<RecyclerViewBlog.MyViewHolder> {

Context ctxt;
private List<Blog> mQuestLIst;
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
class MyViewHolder extends RecyclerView.ViewHolder{

    View View;
    TextView titu,desc,nome,data,carg,qntd,sobre;
    ImageView imag,imag1,imag2,imag3,imag4,imgp;


    public MyViewHolder(View view) {
        super(view);
        View = view;
        ctxt = view.getContext();
        titu = view.findViewById(R.id.titu);
        desc = view.findViewById(R.id.desc);
        nome = view.findViewById(R.id.nome);
        data = view.findViewById(R.id.datt);
        carg = view.findViewById(R.id.carg);
        qntd = view.findViewById(R.id.qntd);
        imag = view.findViewById(R.id.imag0);
        sobre = view.findViewById(R.id.sobre);
        imgp = view.findViewById(R.id.imgp);
    }

    public void setFoto(AccessControlContext ctx, String foto) {
        Glide.with(imgp.getContext()).load(foto).centerCrop().bitmapTransform(new CircleTransform(imgp.getContext())).override(40,40).into(imgp);
    }
    public void setImag(AccessControlContext ctx, String imge) {
        Glide.with(imag.getContext()).load(imge).into(imag);
    }

    public void setData(String hora) {
        //if (data == null)return;
        data.setText(converteTimeStamp(hora));

    }
}

public RecyclerViewBlog(List<Blog> mQuestLIst){
    this.mQuestLIst = mQuestLIst;
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.blog_row, parent, false);
    return new MyViewHolder(view);
}int total=0;
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
   final Blog blog = mQuestLIst.get(position);


    holder.carg.setText(blog.getCarg());
    holder.desc.setText(blog.getDesc());
    //holder.data.setText(blog.getData());
    holder.nome.setText(blog.getNome());
    holder.titu.setText(blog.getTitu());
    holder.sobre.setText(blog.getSobre());
    holder.qntd.setText(blog.getVisitas().getVizualicacoes());
    holder.setData(blog.getData());
    holder.setFoto(getContext(), blog.getFoto());
    holder.setImag(getContext(), blog.getImag1());


    total+=mQuestLIst.get(position).getConta();

    if(position==mQuestLIst.size()-1)
    Log.i("RESULTADO_DA_CONTA", String.valueOf(total));
    holder.View.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent blogstart = new Intent (ctxt, EnterBlog.class);
            blogstart.putExtra("post", blog.getPost());
            blogstart.putExtra("blog", blog.getBlog());
            blogstart.putExtra("position",String.valueOf(position));
            ctxt.startActivity(blogstart);
        }
    });


}

@Override
public int getItemCount()  {
    return mQuestLIst.size();
}

private CharSequence converteTimeStamp(String milesssegundos){
    return DateUtils.getRelativeTimeSpanString(Long.parseLong(milesssegundos), System.currentTimeMillis(), DateUtils.SECOND_IN_MILLIS);
}

}

  • Explain better

  • if you look at the limitToFirst is where I place the amount of items to be downloaded from DB this value increases as roll down... so when I move on to the next activity and back I lose this count...

  • The regency that recyclerview ai. You can put the "complete list"

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.