0

Demo

This is my database. For now only have 2 users but there will be more in the future so I wanted to add row according to the number of users I have in my database. I am able to retrieve the data from fire store but I cant think of a way to add row based on the quantity of my documents.

AdminFragment

final TableLayout table1 = v.findViewById(R.id.table);
final FirebaseFirestore reference = FirebaseFirestore.getInstance();
reference.collection("users").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

    public void onComplete(@NonNull Task<QuerySnapshot> task) {
        if(task.isSuccessful()){
            List<String> list = new ArrayList<>();
            for (QueryDocumentSnapshot document : task.getResult()) {

                TableRow tr = new TableRow(getActivity());
                tr.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
                TextView tv = new TextView(getActivity());
                tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
                TextView tv2 = new TextView(getActivity());
                tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT));
                String email = document.getString("Email");
                String fname = document.getString("FName");
                tv.setText(email);
                tv2.setText(fname);
            }
        }
    }
Barry Michael Doyle
  • 9,333
  • 30
  • 83
  • 143
random
  • 95
  • 1
  • 10
  • What do you mean through "Add table row based on number of documents"? – Alex Mamo Apr 11 '20 at 10:48
  • @Alex Mamo means for example in my collection I have multiple documents and I want to add each documents data into each row. So if I have 5 documents I need to have 5 row. You get it? – random Apr 11 '20 at 12:30
  • In that case, please edit your question and add your database structure as a screenshot and indicate the exact data you want to get. – Alex Mamo Apr 11 '20 at 12:46
  • @Alex Mamo I edited. Perhaps u know the way to do it? – random Apr 11 '20 at 13:33
  • You need a **[ListView](https://stackoverflow.com/a/50228240/5246885)** or even better a **[RecyclerView](https://stackoverflow.com/questions/49277797/how-to-display-data-from-firestore-in-a-recyclerview-with-android/49277842)**. – Alex Mamo Apr 11 '20 at 13:47
  • @Alex Mamo so tablelayout is harder to achieve the result I want? – random Apr 11 '20 at 13:55

0 Answers0