Guidance from Recyclerview

Asked

Viewed 534 times

0

How can I make to recyclerview instead of filling from top to bottom start from bottom to top.

EDITED

when I open my activity with recyclerview and it has several messages so that it exceeds the size of the screen the newer messages stay off the screen only appears scrolling the screen I need it to be contrary the new messages stay on the wheel and the older ones stay on top screen..

     @Override
    protected void onStart () {
        super.onStart();


        FirebaseRecyclerAdapter<Chat, ChatViewHolder> firebaseRecycleAdapter = new FirebaseRecyclerAdapter<Chat, ChatViewHolder>(

                Chat.class,
                R.layout.chat_row,
                ChatViewHolder.class,
                mDatabase


        ) {
            final String user_id = mAuth.getCurrentUser().getUid();
            @Override
            protected void populateViewHolder(ChatViewHolder viewHolder, Chat model, int position) {

                final String post_key = getRef(position).getKey();

                viewHolder.setName(model.getName());
                viewHolder.setComentario(model.getComentario());
                viewHolder.setFtperfil(getApplicationContext(), model.getFtperfil());
                viewHolder.setData(model.getData());


                viewHolder.mView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                        //Toast.makeText(MainActivity.this, post_key , Toast.LENGTH_LONG).show();
                        Intent singleBlogIntent = new Intent(ActivityChat.this, ID_usuario_perfil.class);
                        singleBlogIntent.putExtra("blog_id", post_key);

                        startActivity(singleBlogIntent);


                    }
                });
            }};
    }
        });
        mChatlist.setAdapter(firebaseRecycleAdapter);

    }


    public static class ChatViewHolder extends RecyclerView.ViewHolder {

        View mView;
        ImageButton mLikebtn;
        DatabaseReference mDatabaseLike;
        FirebaseAuth mAuth;

        public ChatViewHolder(View itemView) {
            super(itemView);

            mView = itemView;

            mLikebtn = (ImageButton) mView.findViewById(R.id.like_Btn);


            mDatabaseLike = FirebaseDatabase.getInstance().getReference().child("Like");
            mAuth = FirebaseAuth.getInstance();
            mDatabaseLike.keepSynced(true);

        }


        public void setName (String username) {
            RobotoTextView post_username = (RobotoTextView) mView.findViewById(R.id.nameChat);
            post_username.setText(username);


        }

        public void setComentario (String comentario) {

            TextView post_username = (TextView) mView.findViewById(R.id.messageChat);
            post_username.setText(comentario);
        }
        public void setData (String comentario) {

            TextView post_data = (TextView) mView.findViewById(R.id.dataChat);
            post_data.setText(comentario);
        }

        public void setFtperfil(Context ctx, String ftperfil) {
            CircleImageView post_perfil = (CircleImageView) mView.findViewById(R.id.imageChat);
            Picasso.with(ctx).load(ftperfil).into(post_perfil);

            }
        }}
  • 1

    Suddenly if you change the sort of the list you can solve instead of changing the sort of Recyclerview

  • Change the ordering of the list as @Gabriellocalhost said is the best solution.

  • Good as I can do?

2 answers

1

Friend, make the following changes to your Recyclerview, disregarding the first line of the block:

LinearLayoutManager layout_manager = new LinearLayoutManager(getContext());
layout_manager.setReverseLayout(true);
layout_manager.setStackFromEnd(true);

0

Right understood now, Voce wants to show the values of the end

there is a method called

smoothScrollToPosition

wears like this lista.smoothScrollToPosition(int position)

it will start from the position that Voce set

if it is the last one just save the position value and pass the parameter

if you are using Recycler view for example will do so more or less

recyclerView.smoothscrolltoposition(lista.size());

Since the values during insertion are the last ones then goes straight to the end

I guess that’s what I meant

  • didn’t work out the way I expected, maybe it’s the way I asked.

Browser other questions tagged

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