Как обновить список ListView получаемый с бд Firebase?
Получаю вот так:
//Это в onCreate
final AccAdapter adapter = new AccAdapter();
binding.myList.setAdapter(adapter);
Query myQuery = myRef;
myQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChildName) {
Accounts accounts = snapshot.getValue(Accounts.class);
adapter.add(accounts);
}
@Override
public void onChildChanged(DataSnapshot snapshot, String previousChildName) {
}
@Override
public void onChildRemoved(DataSnapshot snapshot) {
}
@Override
public void onChildMoved(DataSnapshot snapshot, String previousChildName) {
}
@Override
public void onCancelled(DatabaseError error) {
}
});
//Конец onCreate
private class AccAdapter extends ArrayAdapter<Accounts> {
AccAdapter() {
super(MainActivity.this, R.layout.list_design);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
final View view = getLayoutInflater().inflate(R.layout.list_design, null);
final Accounts accounts = getItem(position);
((TextView) view.findViewById(R.id.name)).setText(accounts.text_one);
((TextView) view.findViewById(R.id.price)).setText(accounts.text_two);
return view;
}
}