How to save the size of my recyclerview

0

The size of my recyclerview and settling of the second form is mDatabase.limitToFirst(valor1*valor2) ... valor1 = 1 * valor= 4 = 4

When I roll recyclerview to the end I call EndlessRecyclerViewScrollListener which calls the counter valor1++ valor1 = 2 * valor= 4 = 8 What happens is that each scroll to the end increases by 4 by 4.

The problem is when I move on to the next activity (I open the content), when I come back I want to continue with the same size ... I do not know how to save this result and retrieve it ... I've tried more saved but never used it before then it did not work ... putExtra does not already give the click is done in the activity of the recyclerview ... finally thank to whom to 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);
}

}

    
asked by anonymous 19.10.2017 / 18:15

0 answers