Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – How can I pass all the data in the recyclerview to another activity and show it in the listview or recyclerview Firebase

Posted on November 11, 2022 By

Solution 1 :

Main_activity:

///>>>
    public static String p_username= "username";
    public static String p_date= "date";
    public static String p_comment= "comment";

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

//////.....................................
Random ran=new Random();
                int i=ran.nextInt(photos.length);
                holder.comment_profil.setImageResource(photos[i]);    

                holder.comment_username.setText(model.getUsername());
              
                holder.comment_date.setText(model.getDate());
//>>>
p_username= model.getUsername();
p_date= model.getDate());
p_comment= model.getComment());
//............................................

postfab button:

postfab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent ıntent = new Intent(context,CommentsActivity.class);

                        intent.putExtra("username", p_username);
                        intent.putExtra("date", p_username);
                        intent.putExtra("comment", p_username);
                      
                startActivity(ıntent);
            }
        });

//.....OR......>>>

postfab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent ıntent = new Intent(context,CommentsActivity.class);

                        intent.putExtra(p_username , p_username );
                        intent.putExtra(p_date , p_date );
                        intent.putExtra(p_comment, p_comment);
                      
                startActivity(ıntent);
            }
        });

othars_activity: receive & set all the data

package com.your.package;

import static com.your.package.Main_activity.p_username ;
import static com.your.package.Main_activity.p_date ;
import static com.your.package.Main_activity.p_comment ;
//................................//////

String s_username = p_username;
 String s_date = p_date ;
  String s_comment = p_comment ;
//..............................
            TextView username = v.findViewById(R.id.comment_username);
               TextView date = v.findViewById(R.id.comment_date);
               TextView comment = v.findViewById(R.id.comment_text);
//................................
 set all the data
//...
            username .setText(s_username );
            date .setText(s_date );
             comment.setText(s_comment );

     

Solution 2 :

more simplified:
Main_activity:

///>>>
    private String p_username;
    private String p_date;
    private String p_comment;

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

//////.....................................
Random ran=new Random();
                int i=ran.nextInt(photos.length);
                holder.comment_profil.setImageResource(photos[i]);    

                holder.comment_username.setText(model.getUsername());
              
                holder.comment_date.setText(model.getDate());
//>>>
p_username= model.getUsername();
p_date= model.getDate());
p_comment= model.getComment());
//............................................

postfab button:

postfab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent ıntent = new Intent(context,CommentsActivity.class);

                        intent.putExtra("username", p_username);
                        intent.putExtra("date", p_username);
                        intent.putExtra("comment", p_username);
                      
                startActivity(ıntent);
            }
        });

othars_activity: receive & set all the data

String s_username = getIntent().getStringExtra("username");
 String s_date = getIntent().getStringExtra("date");
  String s_comment = getIntent().getStringExtra("comment");
//..............................
                TextView username = v.findViewById(R.id.comment_username);
               TextView date = v.findViewById(R.id.comment_date);
               TextView comment = v.findViewById(R.id.comment_text);
//................................
 set all the data
//...
                username .setText(s_username );
                date .setText(s_date );
                 comment.setText(s_comment );
 

Problem :

In an activity, I fetch the data from the firebase and print it to the RecyclerView. I want to show all the data in the RecyclerView in another activity again in the RecyclerView. How can I do that? Since 2 activities have the same data, I don’t want to connect firebase in 2.activity and pull data again.

recyclerviewcomment = findViewById(R.id.recyclerviewcomment);
       LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
               linearLayoutManager.setReverseLayout(true);
             linearLayoutManager.setStackFromEnd(true);
             recyclerviewcomment.setLayoutManager(linearLayoutManager);

getcomments();



private void getcomments(){
        FirebaseRecyclerOptions <Comments> options =
                new FirebaseRecyclerOptions.Builder<Comments>()
                        .setQuery(CommentsRef.orderByChild("timestamp"),Comments.class)
                        .build();

        FirebaseRecyclerAdapter<Comments,CommentsViewHolder> adapter
                =new FirebaseRecyclerAdapter<Comments, CommentsViewHolder>(options)
        {

            @Override
            protected void onBindViewHolder(@NonNull final PostActivity.CommentsViewHolder holder, final int position, @NonNull final Comments model) {

                Random ran=new Random();
                int i=ran.nextInt(photos.length);
                holder.comment_profil.setImageResource(photos[i]);    

                holder.comment_username.setText(model.getUsername());
              
                holder.comment_date.setText(model.getDate());

                try {

                    commentwords = model.getComment();
                    for (String word : words) {
                        Pattern rx = Pattern.compile("\b" + word + "\b", Pattern.CASE_INSENSITIVE);
                        commentwords = rx.matcher(commentwords).replaceAll(new String(new char[word.length()]).replace('', '*'));
                    }

                    holder.comment_text.setText(commentwords);


                }catch (Exception e){

                }



            }

            @NonNull
            @Override
            public PostActivity.CommentsViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
                View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.like_comments_model,viewGroup,false);
                PostActivity.CommentsViewHolder viewHolder = new PostActivity.CommentsViewHolder(view);
                return  viewHolder;
            }
        };

        adapter.startListening();

        recyclerviewcomment.setAdapter(adapter);
    }



    public static class CommentsViewHolder extends RecyclerView.ViewHolder{

        TextView comment_username,comment_date,comment_text , commentsanswer;
        ImageView comment_profil;
        View mView ;
        
        public CommentsViewHolder(@NonNull View itemView) {
            super(itemView);
            mView=itemView;

            comment_username = itemView.findViewById(R.id.comment_username);
            comment_date = itemView.findViewById(R.id.comment_date);
            comment_text = itemView.findViewById(R.id.comment_text);
            comment_profil = itemView.findViewById(R.id.comment_profil);
            commentsanswer = itemView.findViewById(R.id.commentsanswer);

        }

        

    }


Comments Model:


public class Comments {

    public String comment , timestamp  , username , date , time , currentUserID ;

    public Comments(){

    }




    public Comments(String comment, String timestamp, String username , String date , String time , String currentUserID) {
        this.comment = comment;
        this.username = username;
        this.timestamp = timestamp;
        this.date = date;
        this.time = time;
        this.currentUserID = currentUserID;


    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }


    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getCurrentUserID() {
        return currentUserID;
    }

    public void setCurrentUserID(String currentUserID) {
        this.currentUserID = currentUserID;
    }


}

When I press the button, I want it to send all the data in the recyclerview to the other activiyt. I just want to send username,date and comments information:

postfab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent ıntent = new Intent(context,CommentsActivity.class);
                startActivity(ıntent);
            }
        });

RecyclerViewinformation for other activity :


R.layout.all_comments_model

TextView username = v.findViewById(R.id.comment_username);
               TextView date = v.findViewById(R.id.comment_date);
               TextView comment = v.findViewById(R.id.comment_text);

Comments

Comment posted by Alex Mamo

How would you like to pass?

READ  [FIXED] How to use GoogleDrive from Android app using FireBase Auth UI?
Powered by Inline Related Posts

Comment posted by Muratcan Yıldız

How could it be. I do not want to download unnecessary data because I downloaded the same data twice in 2 different activities. @AlexMamo

Comment posted by Intent

Have you tried to use an

Comment posted by Muratcan Yıldız

this prints 1 piece of data. Can’t get model.getUsername event because postfab button is not in recyview

Android Tags:android, android-recyclerview, firebase, firebase-realtime-database

Post navigation

Previous Post: [FIXED] android – Please help, after flutter update, (The name ‘MenuItem’ is defined in the libraries) in visual studio
Next Post: [FIXED] react-native: How to remove underline while typing text in TextInput Component on android device?

Related Posts

[FIXED] android – @Composable invocations can only happen from the context of a @Composable function-Jetpack Android
[FIXED] How to run Cuttlefish virtual Android device in selinux permissive mode? Android
[FIXED] android – Regex Outputing the Wrong Index Android
[FIXED] android – When I build a project in flutter it is asking me about update to java 11 , i have jdk 14 istalled , how to fix it in vs code Android
[FIXED] java – android studio recyclerview firebase not showing data Android
[FIXED] android – How Sign out from firebase with dialog Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can VPN be traced by police?
  • Where were Kaiser-Frazer cars built?
  • How do you make gold rose gold paint?
  • What are the newest type of dentures?
  • Can you wear joggers as dress pants?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme