使用GeoQuery和额外数据填充ListView

时间:2018-01-14 19:38:50

标签: android listview

我研究过任何有关此事的话题......但没有发现任何事情...... 有人能帮我吗 ? (抱歉我的英文)

我试图通过GeoQuery显示ListView填充(按距离获取)+ FirebaseQuery(通过geofire使用相同ID密钥获取额外数据)...

private void pickNearby()
{

    GeoFire geofire;
    GeoQuery geoQuery;

    locales.clear();//ArrayList
    database= FirebaseDatabase.getInstance().getReference("locales/");
    geofire = new GeoFire(database);
    geoQuery = geofire.queryAtLocation(new GeoLocation(latitude, longitude), 100.0);
    geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {
        @Override
        public void onKeyEntered(String key, GeoLocation location) {
            if(key!=null) {
                final double laux = location.latitude, longaux = location.longitude;
                Query locationDataQuery = database.child("details").child(key);
                locationDataQuery.addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        //The dataSnapshot should hold the actual data about the location

                        final Elemento elem = dataSnapshot.getValue(Elemento.class); 

                        StorageReference storageReference;
                        databaseImages = FirebaseStorage.getInstance();
                        storageReference = databaseImages.getReferenceFromUrl("//example.appspot.com/images/").child(elem.getId());

                        storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                            @Override
                            public void onSuccess(Uri uri) {
                                elem.setUri(uri);
                            }
                        });  locales.add(elem);


                    @Override
                    public void onCancelled(DatabaseError databaseError) {

                    }

                });

            }
        }

        @Override
        public void onKeyExited(String key) {
        }

        @Override
        public void onKeyMoved(String key, GeoLocation location) {
        }

        @Override
        public void onGeoQueryReady() {
            adapter = new HomeActivity.CustomAdapter((ArrayList<Elemento>) locales);
        }

        @Override
        public void onGeoQueryError(DatabaseError error) {

        }

    });

}

在ArrayList添加所有数据之前调用适配器...任何ideia如何解决它?

0 个答案:

没有答案