Search code examples
androidfirebasefirebase-realtime-databaseandroid-cardview

Dynamically retrieve firebase database text and add text data to a cardview


I want to create an app for leaving comments. For that, I create three pages for my app
The first page is a home activity for refresh and retrieves comment data. The second page is for upload the name, email, title, comment of a commenter. The third page is for viewing the name, title, email of a corresponding comment post which is the clicked post from home activity. On the second page save title, email, name, comment to the firebase database. After that, I want to retrieve all comments on the first page with refresh layout and add it into each and separate card view from the firebase database for every refresh of a layout. And set each unique OnClickListener for all comments.

(Sorry for 500 lines of codes.)

Edit :

I have solve this problem using firebase database.

First upload data using firebase database upload next by next add push() method.

And retrieve data using addValueEventListener()

Add recycler view in home activity and add xml for posts Add linear layout manager. And using inflate method to inflate posts.xml in home activity. Retrive text and add to posts.xml.

Binding data ( click to open seperate posts) using adapter And add put extra method to add post text to binding data activity.

You can add card view in posts.xml not in home activity.

Help me how to do that.


Solution

    1. You need to use a recycler view.

    The recycler view will have an item row with the cardview (and some text views on the card)

    1. In the view holder of the recycler view, set an onclick listener to the card. This will be like setting a listener for all the cards.

    2. Getting data:

    Use firebase listeners and update recycler adapter data when the fire base collection changes.