如何从Firebase或infoWindow中检索特定推送ID子代的所有数据 [英] How to retreive all of the data of a specific pushed ID Child from Firebase or, From a infoWindow

查看:262
本文介绍了如何从Firebase或infoWindow中检索特定推送ID子代的所有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Pu​​sh
生成的节点中获取所有存储的数据。这是我的结构:
$ b



我的所有节点都给这些不同的infoWindows
发送数据:
$ b $ 链接。

  FirebaseUtils.getPostRef()。orderByKey()。addChildEventListener(new ChildEventListener(){
@Override
)public void onChildAdded(final DataSnapshot dataSnapshot,String s){
latitud = dataSnapshot.getValue(Post.class).getLatitud();
longitudinal = dataSnapshot.getValue(Post.class).getLongitud() ;

titulo = dataSnapshot.getValue(Post.class).getTitulo();
costo = dataSnapshot.getValue(Post.class).getCosto();
mes = dataSnapshot .getValue(Post.class).getMes();
numeroDia = dataSnapshot.getValue(Post.class).getDia();
organizadoPor = dataSnapshot.getValue(Pos t.class).getOrganizadoPor();
descripcion = dataSnapshot.getValue(Post.class).getDescripicion();
hora = dataSnapshot.getValue(Post.class).getHora();
minutos = dataSnapshot.getValue(Post.class).getMinutos();

Post post = new Post();
//将所有数据添加到post对象例如post.setLatitud(latitud);

BitmapDescriptor bm = BitmapDescriptorFactory.fromResource(R.mipmap.m5);
LatLng latLng1 =新LatLng(纬度,纵向);
mMarker = new MarkerOptions()。position(latLng1).title(titulo).snippet(costo).icon(bm);
mp.add(mMap.addMarker(mMarker));

//将您的发布数据与标记
mMarker.setTag(post);


}
});

使用此方法检测标记点击次数

<$ ()$ {
$> $ $ $ $ $ $ {
$ on $ {$ b $ on $'$' b $ b Intent intent = new Intent(HomeActivity.this,OtherActivity.class);
Bundle bundle = new Bundle();
//从点击的标记中获取数据并将其附加到
bundle.putSerializable(post,(Post)marker.getTag());
intent.putExtras(bundle);
startActivity(intent);
return true;
}
});
}

在您的OtherActivity中使用它来获取数据。

  Post mPost =(Post)getIntent()。getSerializableExtra(post); 

您的Post模式可能是这样的。

  public class Post实现Serializable {

私有字符串纬度,纵向,角度,titulo,mes, numeroDia,organizadoPor,descripcion,hora,minutos;


public String getLatitud(){
return latitud;
}

public void setLatitud(String latitud){
this.latitud = latitud;
}

public String getLongitud(){
return longitudinal;
}

public void setLongitud(String longitudinal){
this.longitud =
}

public String getCosto(){
return costo;
}

public void setCosto(String costo){
this.costo = costo;
}

public String getTitulo(){
return titulo;
}

public void setTitulo(String titulo){
this.titulo = titulo;
}

public String getMes(){
return mes;
}

public void setMes(String mes){
this.mes = mes;
}

public String getNumeroDia(){
return numeroDia;


public void setNumeroDia(String numeroDia){
this.numeroDia = numeroDia;
}

public String getOrganizadoPor(){
return organizadoPor;
}

public void setOrganizadoPor(String organizadoPor){
this.organizadoPor = organizadoPor;
}

public String getDescripcion(){
return descripcion;

$ b $ public void setDescripcion(String descripcion){
this.descripcion = descripcion;
}

public String getHora(){
return hora;
}

public void setHora(String hora){
this.hora = hora;
}

public String getMinutos(){
return minutos;
}

public void setMinutos(String minutos){
this.minutos = minutos;
}
}


I need to get all the stored data from the nodes generated by Push This is my structure:

All my nodes give data to various infoWindows like these:

Each infoWindow contains data specific to several nodes, what I need is to obtain that data from each of those infoWindows or specific nodes

I need these specific data to put them in another activity, either by getting the data from the node or from the infoWindow How do I do it?

This is the code that gives the data to the infoWindow:

   FirebaseUtils.getPostRef().orderByKey().addChildEventListener(new ChildEventListener() {
                    @Override
                    public void onChildAdded(final DataSnapshot dataSnapshot, String s) {
                        latitud = dataSnapshot.getValue(Post.class).getLatitud();
                        longitud = dataSnapshot.getValue(Post.class).getLongitud();

                        titulo = dataSnapshot.getValue(Post.class).getTitulo();
                        costo = dataSnapshot.getValue(Post.class).getCosto();
                        mes = dataSnapshot.getValue(Post.class).getMes();
                        numeroDia = dataSnapshot.getValue(Post.class).getDia();
                        organizadoPor = dataSnapshot.getValue(Post.class).getOrganizadoPor();
                        descripcion = dataSnapshot.getValue(Post.class).getDescripicion();
                        hora = dataSnapshot.getValue(Post.class).getHora();
                        minutos = dataSnapshot.getValue(Post.class).getMinutos();




                        BitmapDescriptor bm = BitmapDescriptorFactory.fromResource(R.mipmap.m5);
                        LatLng latLng1 = new LatLng(latitud, longitud);
                        mMarker = new MarkerOptions().position(latLng1).title(titulo).snippet(costo).icon(bm);
                        mp.add(mMap.addMarker(mMarker));
   }

I try with this But it only gives me the data of the last infoWindow:

  Post mPost = new Post();
  Intent intent =  new Intent(MainActivity.this, OtherActivity.class);
  intent.putExtra("abc", mPost):

the OtherActivity:

  Intent Intent = getIntent();
   mPost = (Post) intent.getSerializableExtra("abc");

解决方案

Edit your code to be like below.but you need to set data into your post object. you will attach your post data into your marker using mMarker.setTag(post); for more information have a look at this link.

   FirebaseUtils.getPostRef().orderByKey().addChildEventListener(new ChildEventListener() {
                    @Override
                    public void onChildAdded(final DataSnapshot dataSnapshot, String s) {
                        latitud = dataSnapshot.getValue(Post.class).getLatitud();
                        longitud = dataSnapshot.getValue(Post.class).getLongitud();

                        titulo = dataSnapshot.getValue(Post.class).getTitulo();
                        costo = dataSnapshot.getValue(Post.class).getCosto();
                        mes = dataSnapshot.getValue(Post.class).getMes();
                        numeroDia = dataSnapshot.getValue(Post.class).getDia();
                        organizadoPor = dataSnapshot.getValue(Post.class).getOrganizadoPor();
                        descripcion = dataSnapshot.getValue(Post.class).getDescripicion();
                        hora = dataSnapshot.getValue(Post.class).getHora();
                        minutos = dataSnapshot.getValue(Post.class).getMinutos();

                        Post post = new Post();
                        // add all your data to post object e.g post.setLatitud(latitud);

                        BitmapDescriptor bm = BitmapDescriptorFactory.fromResource(R.mipmap.m5);
                        LatLng latLng1 = new LatLng(latitud, longitud);
                        mMarker = new MarkerOptions().position(latLng1).title(titulo).snippet(costo).icon(bm);
                        mp.add(mMap.addMarker(mMarker));

                        // Associate your post data with the marker
                        mMarker.setTag(post);


                        }
                });

use this method to detect marker clicks

private void onMarkerClicked() {
    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
        @Override
        public boolean onMarkerClick(Marker marker) {
            Intent intent = new Intent(HomeActivity.this, OtherActivity.class);
            Bundle bundle = new Bundle();
            // get the data from clicked marker and attach it with the intent 
            bundle.putSerializable("post", (Post) marker.getTag());
            intent.putExtras(bundle);
            startActivity(intent);
            return true;
        }
    });
}

in your OtherActivity use this to get the data .

  Post mPost = (Post) getIntent().getSerializableExtra("post");

your Post model could be like this.

public class Post implements Serializable{

   private String latitud,longitud,costo,titulo,mes,numeroDia,organizadoPor,descripcion,hora,minutos ;


public String getLatitud() {
    return latitud;
}

public void setLatitud(String latitud) {
    this.latitud = latitud;
}

public String getLongitud() {
    return longitud;
}

public void setLongitud(String longitud) {
    this.longitud = longitud;
}

public String getCosto() {
    return costo;
}

public void setCosto(String costo) {
    this.costo = costo;
}

public String getTitulo() {
    return titulo;
}

public void setTitulo(String titulo) {
    this.titulo = titulo;
}

public String getMes() {
    return mes;
}

public void setMes(String mes) {
    this.mes = mes;
}

public String getNumeroDia() {
    return numeroDia;
}

public void setNumeroDia(String numeroDia) {
    this.numeroDia = numeroDia;
}

public String getOrganizadoPor() {
    return organizadoPor;
}

public void setOrganizadoPor(String organizadoPor) {
    this.organizadoPor = organizadoPor;
}

public String getDescripcion() {
    return descripcion;
}

public void setDescripcion(String descripcion) {
    this.descripcion = descripcion;
}

public String getHora() {
    return hora;
}

public void setHora(String hora) {
    this.hora = hora;
}

public String getMinutos() {
    return minutos;
}

public void setMinutos(String minutos) {
    this.minutos = minutos;
}
 }

这篇关于如何从Firebase或infoWindow中检索特定推送ID子代的所有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆