Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – How to populate listView with value coming from firebase

Posted on November 11, 2022 By

Solution 1 :

This statement, List<String> parkings = new ArrayList<>(); is creating a new empty list every time listPopulate is called. You need to move List<String> parkings = new ArrayList<>(); outside of the listPopulate method in order to preserve the ArrayList you’re creating.

example

public List<String> parking;

public void onCreate(xxxxxxxxxxxx){
    XXXXXXXXXXXXXXX

    parking = new ArrayList<>();

}


public void listPopulate(xxxx){
    xxxxxxx
    xxxxxxx
    xxxxxx

}

If you want to preserve the list after closing the app, you’ll need to cache the list locally on the device.

Problem :

I want to populate my list view every time a value is changed with the changed value

The code for ValueEventListener is as

ValueEventListener changeListener3 = new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            String carNumber = dataSnapshot.getValue(String.class);

            listPopulate(carNumber);
        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    };

And the function to populate the value is

public void listPopulate(String carNumber)
    {

        List<String> parkings = new ArrayList<>();

        parkings.add(carNumber);

        final ListView listView = findViewById(R.id.listView2);

        final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,parkings);

        listView.setAdapter(arrayAdapter);
    }

But when I run it the value is updated in listView but it simply replace the current value I want to keep the last value along with new update data

READ  [FIXED] android - Regex Outputing the Wrong Index
Powered by Inline Related Posts
Android Tags:android, firebase, firebase-realtime-database

Post navigation

Previous Post: [FIXED] android – Convert BMP image to PNG or JPG in Java without loading the entire image in memory
Next Post: [FIXED] xml – Android – prevent TextView to push out another element inside LinearLayout

Related Posts

[FIXED] kotlin – Is DefaultClusterRenderer in android-maps-utils broken in v1.2.1? Android
[FIXED] android – Playing Vimeo videos in Flutter Android
[FIXED] java – ARCore: it takes very long to start tracking Android
[FIXED] java – Generate random number for 5min Android
[FIXED] Hiding password text immediately Android Studio Android
[FIXED] android – Cordova – Config.xml – resource-file directive not working Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme