我只检索firestore集合的第一个元素

时间:2018-06-11 04:18:50

标签: android-studio

你好我们现在正在使用firestore在Android工作室的应用程序上工作,我有一个问题。 当我尝试从此集合中检索数据时 enter image description here

并且该函数的代码是:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    v = inflater.inflate(R.layout.fragment_all, container, false);
    tikhcbila = (TextView) v.findViewById(R.id.testou);
    listView = (ExpandableListView) v.findViewById(R.id.list_view_field);
    initData();
    listAdapter = new expandableListViewAdapter(getContext() , listDataHeader , listHashMap);
    listView.setAdapter(listAdapter);
    //Toast.makeText(getContext() , "helloooo" , Toast.LENGTH_SHORT);
    return v;
    //return inflater.inflate(R.layout.fragment_all, container, false);
}

private void initData() {
    listDataHeader = new ArrayList<>();
    listHashMap = new HashMap<>();

    //final ArrayList<String> testUnder = new ArrayList<>();
    //final List<ArrayList<String>> test = new ArrayList<>();

    String idPhone = Settings.Secure.getString(getContext().getContentResolver(),Settings.Secure.ANDROID_ID) ;
    //DocumentReference docRef = db.collection(idPhone).document();

    db.collection(idPhone)
            .get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                   if (task.isSuccessful()) {
                        for (DocumentSnapshot document : task.getResult()) {
                            //Log.d(TAG, document.getId() + " => " + document.getData());

                            homework hw = document.toObject(homework.class);

                            testUnder.add(hw.getDescription());
                            testUnder.add(hw.getDate());
                            testUnder.add(hw.getType());

                            test.add(testUnder);
                            testouuu+= hw.getDescription() + " " + hw.getDate() + " " + hw.getType() + "    ";

                        }
                        tikhcbila.setText(testouuu);

                    }
                    else {
                        Log.w(TAG, "Error getting documents.", task.getException());
                    }
                }
            });





    listDataHeader.add("All");


    listHashMap.put(listDataHeader.get(0),test);

}

结果是:

enter image description here

问题是它没有检索到它只检索第一个元素的所有文档并保存它并将其复制到列表视图的其他项目中 ps:对不起我的英文

0 个答案:

没有答案