簡體   English   中英

加載Firebase數據庫時顯示進度條

[英]Showing progress bar while loading Firebase database

我在我的應用程序中使用Firebase實時數據庫。 我有listView和adapter,適配器的每個視圖都從Firebase數據庫加載一項。 但是加載所有數據需要幾秒鍾(每個項目都有圖像和名稱)。 因此,我想顯示進度條或要向用戶顯示的內容,但我不知道將其放在何處。

我考慮過使用asynctask之類的東西,但是問題是我真的不知道將數據加載到哪里。 我將子事件偵聽器附加到Firebase數據庫引用對象,因此,每次添加新子項時,適配器都將更新,但是我不知道如何知道所有子項都已完成加載。

希望你能理解我並幫助我。

看到這是設置一些數據的功能:-

     private void addUserChangeListener() {
    *** you can initialize your progress dialog here
                // User data change listener


      mFirebaseDatabase.child(userId).addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    User user = dataSnapshot.getValue(User.class);


                    // Check for null
                    if (user == null) {
                        Log.e(TAG, "User data is null!");
                        return;
                    }

                    Log.e(TAG, "User data is changed!" + user.name + ", " + user.email);
    *** here you can check if the progress dialog is not null then close your progress dialog here

                    // Display newly updated name and email
                    txtDetails.setText(user.name + ", " + user.email);

                    // clear edit text
                    inputEmail.setText("");
                    inputName.setText("");

                    toggleButton();
                }

                @Override
                public void onCancelled(DatabaseError error) {
                    // Failed to read value
***also close your progress dialog here
                    Log.e(TAG, "Failed to read user", error.toException());
                }

            });
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM