Firebase Android Listview Not Being Displayed

Firebase Android ListView not being displayed

The problem in your code lies in the fact that you have in your CustomListAdapter class a field named ItemName but you are using a getter named getItemName(), which is not correct since Firebase is looking in the database for a field named itemName and not ItemName. See the lowercase i letter vs. capital letter I?

There are two ways in which you can solve this problem. The first one would be to change your model class by renaming the fields according to the Java Naming Conventions. So you model class should look like this:

public class CustomListAdapter {
private String itemName, quantity, serialNo, supplierName, supplierEmail, supplierPhone;

public CustomListAdapter() {}

public CustomListAdapter(String itemName, String quantity, String serialNo, String supplierName, String supplierEmail, String supplierPhone) {
this.itemName = itemName;
this.quantity = quantity;
this.serialNo = serialNo;
this.supplierName = supplierName;
this.supplierEmail = supplierEmail;
this.supplierPhone = supplierPhone;
}

public String getItemName() { return itemName; }
public String getQuantity() { return quantity; }
public String getSerialNo() { return serialNo; }
public String getSupplierName() { return supplierName; }
public String getSupplierEmail() { return supplierEmail; }
public String getSupplierPhone() { return supplierPhone; }
}

See in this example, there are private fields and public getters. There is also a simpler solution, to set the value directly on public fields like this:

public class CustomListAdapter {
public String itemName, quantity, serialNo, supplierName, supplierEmail, supplierPhone;
}

Now just remove the current data and add it again using the correct names. This solution will work only if you are in testing phase.

There is also the second approach, which is to use annotations. So if you prefer to use private fields and public getters, you should use the PropertyName annotation only in front of the getter. So your CustomListAdapter class should look like this:

public class CustomListAdapter {
private String ItemName;
private String Quantity;
private String SerialNo;
private String SupplierName;
private String SupplierEmail;
private String SupplierPhone;

public CustomListAdapter() {}

public CustomListAdapter(String itemName, String quantity, String serialNo, String supplierName, String supplierEmail, String supplierPhone) {
ItemName = itemName;
Quantity = quantity;
SerialNo = serialNo;
SupplierName = supplierName;
SupplierEmail = supplierEmail;
SupplierPhone = supplierPhone;
}

@PropertyName("ItemName")
public String getItemName() { return ItemName; }
@PropertyName("Quantity")
public String getQuantity() { return Quantity; }
@PropertyName("SerialNo")
public String getSerialNo() { return SerialNo; }
@PropertyName("SupplierName")
public String getSupplierName() { return SupplierName; }
@PropertyName("SupplierEmail")
public String getSupplierEmail() { return SupplierEmail; }
@PropertyName("SupplierPhone")
public String getSupplierPhone() { return SupplierPhone; }
}

List View is not showing my items from FIREBASE

In your onDataChange method you never update your ArrayAdpater with the values from list_groups. You should call addAll on your ArrayAdpater before calling notifyDataSetChanged()

Something like:

arrayAdapter.addAll(list_groups);
arrayAdapter.notifyDataSetChanged()

ListView does not show data from firebase

You need to set new list to adapter, which you are not doing into your current code. Modify below line

adapterCities = new ArrayAdapter<>(CitiesList.this, android.R.layout.simple_list_item_1);
ListViewCities.setAdapter(adapterCities);

as

adapterCities = new ArrayAdapter<>(CitiesList.this, android.R.layout.simple_list_item_1, ArrayListCities);
ListViewCities.setAdapter(adapterCities);

As a side note, try to follow coding style guidelines.

Firebase Data not Showing in ListView on Android

Ok, try this:

1) Move the array declaration out of your onCreate() method, make it a member variable of your activity so you don't have to declare it final:

ArrayList<Word> words = new ArrayList<Word>();

2) Add the adapter declaration as a member variable of your class as well and instantiate the adapter before you access the database:

    adapter = new WordAdapter(this, words);
ListView listView = findViewById(R.id.notification);
listView.setAdapter(adapter);

3) Finally, after you've added all data to the list, call notifiyDatasetChanged() no the adapter to refresh the list.

for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) {
Word value = postSnapshot.getValue(Word.class);
words.add(value);
// TODO: handle the post
}
adapter.notifyDatasetChanged();

ListView not displaying anything from Firebase Database

You have to pass a query, not the database reference in the setQuery method of FirebaseListOptions, like this,

Query query = FirebaseDatabase.getInstance().getReference().child("your node value");

and then pass this query like this,

FirebaseListOptions<ChatMessage> options = new FirebaseListOptions.Builder<ChatMessage>()
.setQuery(query, ChatMessage.class)
.setLayout(R.layout.list_item)
.build();

Also don't forget to startListen in onStart and stopListen in onStop, like this:

@Override
protected void onStart() {
super.onStart();
adapter.startListening();
}

@Override
protected void onStop() {
super.onStop();
adapter.stopListening();
}

Firebase database not showing in listview

Use addListenerForSingleValueEvent instead of addValueEventListener .

Then do,

adapter = new ListViewAdapter(getActivity(), arraylist);
mListView.setAdapter(adapter);

after initiallizing recycler view,
and then

adapter.notifyDataSetChanged();

after getting data on onDataChange()

Firebase not showing data to a listview

To get the name out of your Firebase database, please use the following code:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference productsRef = rootRef.child("Products");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
List<String> list = new ArrayList<>();
for(DataSnapshot ds : dataSnapshot.getChildren()) {
String name = ds.child("name").getValue(String.class);
list.add(name);
Log.d("TAG", name);
}
Log.d("TAG", list);
}

@Override
public void onCancelled(DatabaseError databaseError) {}
};
productsRef.addListenerForSingleValueEvent(eventListener);

Yout output will be:

ps4
Xbox
//and so on


Related Topics



Leave a reply



Submit