第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

從 Android 上的 Firebase Firestore 查詢對(duì)象列表

從 Android 上的 Firebase Firestore 查詢對(duì)象列表

哈士奇WWW 2021-08-06 10:02:31
我正在嘗試創(chuàng)建一種從我的Cloud Firestore database. 然后我會(huì)RecyclerView用上述列表設(shè)置一個(gè)適配器,它應(yīng)該能很好地顯示。截止目前,RecyclerView空空如也。(我還RecyclerView用虛擬項(xiàng)目測(cè)試了它們,它們顯示得很好)在我的方法結(jié)束時(shí),項(xiàng)目列表仍然是空的。日志以奇怪的順序顯示(最后一個(gè)日志顯示在其他日志之前)。日志順序讓我懷疑在偵聽(tīng)器中運(yùn)行了一些單獨(dú)的線程。我不確定如何同步它們。private List<Project> projects;private FirebaseFirestore db;...在onCreateView()(我正在處理一個(gè)片段): db = FirebaseFirestore.getInstance(); queryAllProjects(); recyclerView.setAdapter(new ProjectRecyclerViewAdapter(projects, ...... private void queryAllProjects() {        projects = new ArrayList<>();         //I've already tried to make a local list and return that, however,         //the compiler would force me to declare the list as final here, and it wouldn't solve anything.        db.collection("projects")                .get()                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {                    @Override                    public void onComplete(@NonNull Task<QuerySnapshot> task) {                        if (task.isSuccessful()) {                            for (QueryDocumentSnapshot document : task.getResult()) {                                Log.d(TAG, document.getId() + " => " + document.getData());                                Project project = document.toObject(Project.class);                                projects.add(project);                            }                            Log.d(TAG, "After for loop: " + projects.toString());                             //Here the list is OK. Filled with projects.                             //I'd like to save the state of the list from here                        } else {                            Log.d(TAG, "Error getting document: ", task.getException());                            Toast.makeText(getContext(), R.string.error, Toast.LENGTH_SHORT).show();                        }                    }                });這是我一直在關(guān)注的官方文檔https://firebase.google.com/docs/firestore/query-data/get-data#custom_objects
查看完整描述

2 回答

?
猛跑小豬

TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊

projects.add(project);

adapter.notifyDataSetChange()

添加列表后調(diào)用 notifyDataSetChange()


查看完整回答
反對(duì) 回復(fù) 2021-08-06
  • 2 回答
  • 0 關(guān)注
  • 175 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)