使用查询

时间:2019-05-22 16:13:38

标签: android firebase-realtime-database firebaseui

我想通过使用查询从Firebase获取数据。我能够检索到,并且在android的控制台中显示,但是在android应用程序中却没有显示。在android中,它向我显示了最后使用的数据。

usuarios.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        for (DataSnapshot ds:dataSnapshot.getChildren()){

            DatabaseReference eventos = ds.getRef().child("eventos");
            System.out.println("eventos:"+eventos);

            for (int i = 0; i < categorias.size();i++){
                String categoria = categorias.get(i).toString();

                if (value.equals(categoria)){
                    eventoFirebaseListOptions = new FirebaseListOptions.Builder<Evento>()
                            .setQuery(eventos,Evento.class)
                            .setLayout(R.layout.layout_evento)
                            .setLifecycleOwner(getViewLifecycleOwner())
                            .build();
                }else if (value!=categoria){
                    eventoFirebaseListOptions = new FirebaseListOptions.Builder<Evento>()
                            .setQuery(eventos.orderByChild("categoria").equalTo(value),Evento.class)
                            .setLayout(R.layout.layout_evento)
                            .setLifecycleOwner(getViewLifecycleOwner())
                            .build();
                }
            }

            final FirebaseListAdapter<Evento> adapter = new FirebaseListAdapter<Evento>(eventoFirebaseListOptions) {
                @Override
                protected void populateView(View v, Evento evento, int position) {

                    //Muestra el value de cada campo de la base de datos
                    TextView txtTitol = v.findViewById(R.id.txtTitol);
                    TextView txtDescripcio = v.findViewById(R.id.txtDescripcion);
                    ImageView imageView = v.findViewById(R.id.imageView);


                    txtTitol.setText(evento.getTitol());
                    txtDescripcio.setText(evento.getDescripcion());
                    Glide.with(getContext()).load(evento.getImagenUrl()).into(imageView);

                }
            };

            ListView lvEventos = view.findViewById(R.id.lvEventos);
            lvEventos.setAdapter(adapter);

我想获取具有“ SMIX”类别的数据,该类别是动态的,也可能是另一个类别。

这是我的JSON数据

  "usuarios" : {
    "UvTCjIYMA0btE14QHz7twbdN7zT2" : {
      "eventos" : {
        "-LdPfYoRre18oGpd3Oda" : {
          "caducidad" : "2019-04-26",
          "categoria" : "SMIX",
          "descripcion" : "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the",
          "horaDelEvento" : "12:12",
          "imagenUrl" : "https://firebasestorage.googleapis.com/v0/b/english-app-b2170.appspot.com/o/usuarios%2FUvTCjIYMA0btE14QHz7twbdN7zT2%2Fimagenes%2Fpexels-photo-160107.jpeg?alt=media&token=f0b7b573-8ca4-4fd2-a5e4-da43b967ff4b",
          "sitioDelEvento" : "Aula 33",
          "titol" : "Lorem Ipsum"
        },
        "-LfKmyXSFiR6MwKQZeJQ" : {
          "caducidad" : "2019-06-08",
          "categoria" : "DAM",
          "descripcion" : "muy fácil",
          "horaDelEvento" : "16:00",
          "imagenUrl" : "https://firebasestorage.googleapis.com/v0/b/english-app-b2170.appspot.com/o/usuarios%2FUvTCjIYMA0btE14QHz7twbdN7zT2%2Fimagenes%2FCaptura%20de%20pantalla%202019-05-17%20a%20las%2016.48.58.png?alt=media&token=f8da7ac8-2a64-45ee-8b4f-79f66f431e54",
          "sitioDelEvento" : "instituto",
          "titol" : "examen"
        }
      }
    },
    "hzqvjnkTdJcyTOPUcEMrAmvEXUo1" : {
      "eventos" : {
        "-LfWFcaFgk4Apwr0zqqZ" : {
          "caducidad" : "1212-12-12",
          "categoria" : "DAM",
          "descripcion" : "Fifa",
          "horaDelEvento" : "12:12",
          "imagenUrl" : "https://firebasestorage.googleapis.com/v0/b/english-app-b2170.appspot.com/o/usuarios%2FhzqvjnkTdJcyTOPUcEMrAmvEXUo1%2Fimagenes%2FCaptura%20de%20pantalla%202019-05-22%20a%20las%2018.07.06.png?alt=media&token=ba173429-affb-4578-85bb-ca73e17d8cdf",
          "sitioDelEvento" : "Aula 33",
          "titol" : "Fifa"
        }
      }
    }
  }
}

0 个答案:

没有答案