popular Spinner by Firebasefirestore Android

Asked

Viewed 40 times

0

Good morning guys,

I am trying to popular a spinner by the data searched from Firebasefirestore, however when starting the application the spinner becomes "white", when clicking on it shows the list of items but it is not possible to select any of them, already I saw all posts of the stack in relation to this and other sites, if possible please help me.

XML:

<Spinner
    android:id="@+id/spinnerProducts"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"/>

Function that fetches the data

public static List<String> getListProducts() {
    final List<String> titleList = new ArrayList<String>();

    CollectionReference collectionRef = DBConnection.getFirebaseFirestore().collection("Products");
    Query query = collectionRef.orderBy("id", Query.Direction.ASCENDING);

    query.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
        @Override
        public void onSuccess(QuerySnapshot queryDocumentSnapshots) {

            for (DocumentSnapshot readData: queryDocumentSnapshots.getDocuments()) {
                    String titlename = (String) readData.get("Name");
                System.out.println(titlename);
                    titleList.add(titlename);
            }

        }
    });

    return titleList;
}

Populating the spinner:

spinnerProducts = root.findViewById(R.id.spinnerProducts);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, ProductsDao.getListProducts());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinnerProducts.setAdapter(adapter);

Application when launching the application:

inserir a descrição da imagem aqui

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.