Display FIREBASE image in a LISTVIEW

Asked

Viewed 304 times

1

I would like to know how to recover an image in firebase and put in a listview, I saw here some similar questions, followed the answers that are in them but none worked. I saw that a boy said he used a recyclerView and it worked, but I could not use it, could someone help me? follows below the code

ADAPTER

 public View getView(int position, View convertView, ViewGroup parent) {
        View view = act.getLayoutInflater().inflate(R.layout.lista_sessao_personalizada, parent, false);

        Sessoes sessao = sessoes.get(position);

        TextView nome = (TextView) view.findViewById(R.id.lista_sessao_personalizada_nome);
        TextView descricao = (TextView) view.findViewById(R.id.lista_sessao_personalizada_descricao);
        final ImageView imagem = (ImageView) view.findViewById(R.id.lista_sessao_personalizada_imagem);

        nome.setText(sessao.getNomeSessao());
        descricao.setText(sessao.getDescricaoSessao());

        firebase = ConfiguracaoFirebase.getFirebase().child("configuracao").child("telaInicial").child("calendario");

        ValueEventListener post = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                String imagemFire = dataSnapshot.getValue().toString();
                Glide.with(act).load(imagemFire).into(imagem);
                Log.i("imagem", imagemFire);

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        };
        firebase.addValueEventListener(post);

       // Glide.with(act).load(imagemFire).into(imagem);

        return view;
    }
}

Activity receiving the Adapter

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        logoImg = findViewById(R.id.logo_doeamor_id);

        firebase = ConfiguracaoFirebase.getFirebase().child("configuracao").child("telaInicial").child("logo");

        ValueEventListener post = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                String imagem = dataSnapshot.getValue().toString();
                Glide.with(getApplicationContext()).load(imagem).into(logoImg);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        };
        firebase.addValueEventListener(post);

        sessoes = todasAsSessoes();
        listaDeSessoes = (ListView) findViewById(R.id.listaDeSessoes);

        AdapterPersonalizado adapter = new AdapterPersonalizado(sessoes, MainActivity.this);

        listaDeSessoes.setAdapter(adapter);


    }

and the image comes out like this:

inserir a descrição da imagem aqui

1 answer

1

Colleague, with the link below you will understand how to create step-by-step, and in several ways, a Recycleview, which is the same Listview, but much more improved, optimized and simpler to implement.

https://medium.com/android-dev-br/listas-com-recyclerview-d3f41e0d653c

A tip that I give you, is you use the Picaso api, link below, in it you download any firebase image without any problem and all images remain cached, which will make your app have an excellent performance.

http://square.github.io/picasso/

Create an array somehow with the links and feed your Recycleview with it. That’s what I would do.

Browser other questions tagged

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