Can you help me in this problem, I try to display data from in firebase in Listv
public class MainActivity extends AppCompatActivity{
ListView listView;
FirebaseDatabase firebaseDatabase;
DatabaseReference databaseReference;
ArrayList arrayList = new ArrayList<>();
ArrayAdapter arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firebaseDatabase = FirebaseDatabase.getInstance();
databaseReference = firebaseDatabase.getReference("Users");
listView = (ListView) findViewById(R.id.lists);
Toast.makeText(this, "ok", Toast.LENGTH_SHORT).show();
databaseReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
String value=dataSnapshot.getValue(String.class);
arrayList.add(value);
arrayAdapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, arrayList);
listView.setAdapter(arrayAdapter);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}}
This listener is actually used for lists, so its not from the listener. Also since the user is not authenticated you need to change the rules in your database to :-
{
"rules": {
".read": "true",
".write": "true"
}
}