AlertDialog with ListView in FireBase

0

Hello, I'm new to Android Programming. I'm trying to put a custom AlertDialog on an activity in this AlertDialog I want to put a listView that calls items present in my FireBase database. But when I click to open the Error AlertDialog and to. Here is the code for the class:

package com.cpcp.jaykl.pesquisacpcp;

import android.content.DialogInterface;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.google.firebase.FirebaseApp;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;
import java.util.List;
import java.util.zip.Inflater;

public class ListaProdutos extends AppCompatActivity {
private static FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;
List<BdProdutos> listProdutos = new ArrayList<BdProdutos>();
ArrayAdapter<BdProdutos> arrayAdapterProdutos;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lista_produtos);
    inicializarFireBase();
    FloatingActionButton fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view)
        {
            chamaTela();
        }
    });

}
private void inicializarFireBase()//inicializa o fireBase
{
    if(firebaseDatabase == null)
    {
        firebaseDatabase = FirebaseDatabase.getInstance();
    }
    FirebaseApp.initializeApp(ListaProdutos.this);
    databaseReference = firebaseDatabase.getReference();
}

private void chamaTela()
{
    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    LayoutInflater inflater = this.getLayoutInflater();
    final View dialogView = inflater.inflate(R.layout.teste_dialog, null);
    dialogBuilder.setView(dialogView);
    dialogBuilder.setMessage("Testando Tela");

    final ListView listViewTeste = (ListView)findViewById(R.id.listViewTeste);

    databaseReference.child("Produtos").orderByChild("nome").addValueEventListener(new ValueEventListener()
    {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot)
        {
            for (DataSnapshot objSnapshot : dataSnapshot.getChildren())
            {
                BdProdutos bdProdutos = objSnapshot.getValue(BdProdutos.class);
                listProdutos.add(bdProdutos);
                arrayAdapterProdutos = new ArrayAdapter<BdProdutos>(ListaProdutos.this,
                        android.R.layout.simple_list_item_1, listProdutos);
                listViewTeste.setAdapter(arrayAdapterProdutos);
            }

        }

        @Override
        public void onCancelled(DatabaseError databaseError)
        {

        }
    });

    dialogBuilder.setPositiveButton("Ok", new DialogInterface.OnClickListener()
    {
        @Override
        public void onClick(DialogInterface dialog, int which)
        {


        }
    });
    AlertDialog b = dialogBuilder.create();
    b.show();
}

}

    
asked by anonymous 19.05.2018 / 23:53

0 answers