I have data that consist of Unique ID, UserName, Email, etc, where only UID is unique and is used as Key as while searching DB user needs to enter UID.
So if I see all DB via application it shows Username Twice as there are different UID. Instead, I need a username to appear once only.
sample screenshot of DB:
Firebase-root
|
--- Users
|
--- 9638527410
| |
--- userName: "John Doe"
| |
--- emailAddress: "John@Doe.com"
|
--- 9876543210
| |
--- userName: "John Doe"
| |
--- emailAddress: "John@Doe.com"
Now when I'm trying to fetch data app is showing Android App Fetch Result
Sample of code
private void fetch_items() {
try {
ListView listView_items = findViewById(R.id.c_listView);
Query query = databaseReference.orderByChild("username");
FirebaseListOptions<firebase_username> firebaseListOptions = new FirebaseListOptions.Builder<firebase_username>().setQuery(query,firebase_username.class). setLayout(android.R.layout.activity_list_item).setLifecycleOwner(this).build();
FirebaseListAdapter<firebase_username> firebaseListAdapter =
new FirebaseListAdapter<firebase_username>(firebaseListOptions) {
@Override
protected void populateView(@NonNull View v, @NonNull firebase_username model, int position) {
((TextView) v.findViewById(android.R.id.text1)).setText(model.get_username());
}
};
listView_items.setAdapter(firebaseListAdapter);
} catch (Exception e) {
Log.e("Error", e.toString());
}
}