How to populate an ArrayAdapter with a List of objects from a Firebase Database?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to populate an ArrayAdapter with a List of objects from a Firebase Database?



I'm trying to populate my ListView with User objects from Firebase Database. I've seen some people use RecyclerView but I cannot get RecyclerView to work on my Android Studio (maybe i'm using incompatible dependencies).



Anyway here is my code:


// necessary imports

public class List extends AppCompatActivity

ListView usersList;
private DatabaseReference userDatabase;
ArrayList<String> list = new ArrayList<>();


@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);

usersList = (ListView) findViewById(R.id.list_users);


userDatabase = FirebaseDatabase.getInstance().getReference().child("Users");






@Override
protected void onStart()
super.onStart();

// Populate ArrayAdapter with User objects from Firebase Database.
ArrayAdapter<Users> Adapter = new ArrayAdapter<Users>(this, Users.class, android.R.layout.simple_expandable_list_item_1, userDatabase)

// Populate here, don't know what to do.


;

usersList.setAdapter(Adapter);

usersList.setOnItemClickListener(new AdapterView.OnItemClickListener()
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
Users.connectTo = list.get(i);
Intent chatActivity = new Intent(List.this, ChatActivity.class);
startActivity(chatActivity);


);















By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS