Hi, I have a PPP where I keep information about a notice in FireBase, when I have it and keep it fairly well and will keep me on each user sending notices.
Now I need to show all that information on a different screen, I tried to do it with a ListView but it does not do anything, any idea of where the error might be? Or some way to make it better?
public class VerAviso extends MenuAvisos
{
List<Aviso> avisos;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.veraviso);
FirebaseDatabase database = FirebaseDatabase.getInstance();
FirebaseUser user = firebaseAuth.getInstance().getCurrentUser();
final ArrayAdapter<Aviso> adapter;
list = (ListView)findViewById(R.id.listview);
adapter = new ArrayAdapter<Aviso>(this, android.R.layout.simple_list_item_1);
list.setAdapter(adapter);
database.getReference("Aviso").child(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
avisos.clear();
for(DataSnapshot snapshot :
dataSnapshot.getChildren()){
Aviso aviso2 = snapshot.getValue(Aviso.class);
avisos.add(aviso2);
}
adapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
If necessary, the method which I use to store the Data is this.
private void saveInformation()
{
//getting current user
FirebaseUser user = firebaseAuth.getInstance().getCurrentUser();
Aviso avisos = new Aviso();
//Getting values from database
avisos.setAviso(aviso1.getText().toString());
avisos.setDescripcion(textDes.getText().toString());
avisos.setUbicacion(textubi.getText().toString());
FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference myRef = database.getReference("Aviso").child(user.getUid());
Aviso aviso2 = new Aviso(avisos.getAviso(),avisos.getDescripcion(),avisos.getUbicacion());
myRef.push().setValue(aviso2);
//displaying a success toast
Toast.makeText(this, "Guardando informacion del aviso, espera...", Toast.LENGTH_LONG).show();
}