0

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());
        }
    }
a.i.s
  • 1
  • 4
  • What is your question? It typically helps if you show the [minimal code that reproduces the problem](http://stackoverflow.com/help/mcve). – Frank van Puffelen May 09 '20 at 14:05
  • See for an example of somebody implementing a click listener and then getting the item for that click here: https://stackoverflow.com/questions/41077476/cant-use-getref and my answer here: https://stackoverflow.com/a/34113070 – Frank van Puffelen May 10 '20 at 16:44
  • I know how to implement click listener I just need If see all DB via application it shows Username Twice as there are different UID. Instead, I need a username to appear once only. – a.i.s May 11 '20 at 16:05
  • You can [hide the elements](https://stackoverflow.com/questions/41223413/how-to-hide-an-item-from-recycler-view-on-a-particular-condition/41223693) that contain duplicate names. But there's nothing built into Firebase or FirebaseUI for that. – Frank van Puffelen May 11 '20 at 16:25
  • Ok, thanks. BTW I think I'm more clear with my question now. To hide duplicate values. or show them only once. As I was thinking of List and populate if but for DB I think it is bad practice as it will be a memory leak. – a.i.s May 11 '20 at 16:29
  • Instead of Array-List, I implemented HashSet for a smooth experience and achieved what I needed. – a.i.s May 11 '20 at 17:08

0 Answers0