Android S7E7 : Firebase ListView - Save then Scroll to Last Added Item

preview_player
Показать описание
This an android firebase listview tutorial and example.We see how write/save, read/retrieve items to firebase database then smooth scroll to last added or saved item in the listview. We are using Firebase Realtime database for data persistence and custom listview for rendering this list of data.

This is tutorial that was requested and as you know these days we are covering almost all tutorials that are requested by community members.

Firebase Database is a popular realtime database and very powerful quite easy to use.

I take you guys through all the steps from setting up firebase, creating firebase app in the firebase console and finally to saving then retrieving data to and from firebase.

The data is written and read in realtime and the listview is always synced with the latest updates from firebase.

How to Save Data to Firebase Database
Saving data to Firebase database is very easy. This saving is sometimes called a `write` operation. Or `insert`.

We can easily save a custom object like say `User` or `Teacher` into firebase database. Then these will be stored in a JSONObject-like nodes.

In Firebase multiple users can save data at the same time by pushing the data via the `push()` method.

But first you need the Child node(like a Table) where we push that data. We can get it from our `DatabaseReference` object

We set the value we want to push or save to Firebase database via the `setValue()` method

How to Read/Retrieve Data From Firebase
There are two main ways of reading data from Firebase database:
1. Using ChildEventListener - Read and Return data node by node.
2. Uisng ValueEventListener - Read all data at once and return it.

The most commonly used way is the `ChildEventListener` method. However, our app in this case massively suits us to do it the second way, using the `ValueEventListener`. Why?

Well remember we want to write and read data to firebase then scroll over to the last added item. So we need all the data so that we can only scroll at the end, to the last added item.

So first we create a method called `retrieve()`. This method will retrieve data and bind to our ListView.

How to Smooth Scroll ListView to Recently Added Firebase Item

To scroll to the last added item in our ListView, we will make our ListView only scroll to the specified adapter position only when the user interface thread is ready.

Othwerwise we risk the scroll not happening as we expect since the user interface is going to be doing alot at this time.

We are interested in this case in the latter, enqueueing. The Handler does this just within the same thread.

So our scroll task will be enqueued and performed only when the UI thread is ready.

Hey, please watch the tutorial or read the article.
Рекомендации по теме
Комментарии
Автор

GET RE-USABLE FULL APP TEMPLATE - Create any CRUD app you like.

Oclemy here guys. I have just released a much needed course for performing all CRUD operations, search and pagination using Retrofit against MySQL. I have designed this to be a full working app that you can use as a template.

TARGET STUDENTS:
1. Beginners/Intermediates who want to create their first full app.
2. Programmers who want a practical guide to master Retrofit.
3. Students who have a looming assignment/project and want a quick easy to understand project they can modify.
4. Anybody who wants to create a full CRUD app based on any idea.

WHERE IS IT?

I have just released it in udemy course. It's a 70 lecture practical step by step guide, realtime coding from scratch as we explain. It's the only Android MySQL CRUD course on udemy.

WHY GET IT NOW?

2. Next week am releasing a version for Firebase with Images/Text Full CRUD with pagination and search, You will get source code for that for free before I upload it to udemy.



ProgrammingWizards
Автор

I used parts of this list view with an app I am creating in the unlikely event it makes any money I will give some to you, for the time being a subscribe and a big thank you for a fantastic tutorial is going to have to do.

joshemarsden
Автор

Grate Sir, THE KING OF YOUTUBE, ): , ,, Sir please start new android php tutorials, a simple blog app user register phone number with verification (fairabse), user profile, upload profile image, edit profile details, user upload image with description in post (Like Facebook), this post see all user, sir please created this tutorials, we are, Please Start This Weeks, Create THis Tutorial PART PART

shababkm
Автор

nice and awesome video
please kindly save and add image together with text into listview

Sport-word
Автор

Hi sir, how to save scroll position of recylerview activity when we go to next detail activity by clicking itemclicklistener from list of items in recyclerview and restore position when we come back to recylerview activity...sir can you please help me

dasisridarshan
Автор

dude tq ...and I have a simple question pls clr this one ... I know that how to retrieve data and show it in a listview ... I done it to show all the keys in my database ...but when I click the the key ..it wanna toast me the value of the respective key ...I don't know how to do it ...can u pls help me dude

aswinvenkat
Автор

Please update source code link. Giving link is not working

JamshedAli-jouf
Автор

Hi! Could you recommend a method of how I could add a delete or edit functionality?

sineadroe
Автор

error generated while entering data of teacher

rajchokshi