title: Getting Firebase Listview position
body: <p>I have a User class for populate a listview. This is the way i create User node</p>
  
  <pre><code>        currentUser= FirebaseAuth.getInstance().getCurrentUser().getUid();
      DatabaseReference usersDatabase= FirebaseDatabase.getInstance().getReference("Users");
      usersDatabase.keepSynced(true);
      User users= new User(FirebaseAuth.getInstance().getCurrentUser().getDisplayName());
      String key = currentUser;
      usersDatabase.child(key).setValue(users);
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/NjIcX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NjIcX.png" alt="Node Image"></a></p>
  
  <p>All works good... until i want to work with values retrieved from this listview. I set up a way for long click items of listview for get the value, but it doesn't work.</p>
  
  <pre><code>@Override
          public void onItemCheckedStateChanged(ActionMode mode, int position,
                                                long id, boolean checked) {
              adminToAdd = new ArrayList&lt;&gt;();
              if (checked) {
                  adminToAdd.add(uAdapter.getItem(position));
              } else {
                  adminToAdd.remove(uAdapter.getItem(position));
              }
              uAdapter.notifyDataSetChanged();
  
              int checkedItems = listView.getCheckedItemCount();
              if (checkedItems==1){
                  mode.setTitle(String.valueOf(checkedItems) + getString(R.string.selected));
              } else {
                  mode.setTitle(String.valueOf(checkedItems) + getString(R.string.more_selected));
              }
  
          }
      });
      uAdapter= new UsersAdapter(this, User.class, R.layout.one_user, FirebaseDatabase.getInstance().getReference("Users"));
      listView.setAdapter(uAdapter);
  
      listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
  
          @Override
          public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1,
                                         int position, long arg3) {
              selectedPosition = position;
              final ListView list = (ListView) arg0;
              list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
              list.setItemChecked(position, true);
              return true;
          }
      });
  </code></pre>
  
  <p>I was supposing that with this code i can take position for each values of adminToAdd ArrayList. Then, i use it for set another database child called "Admins". The way:</p>
  
  <pre><code>@Override
          public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) {
              // TODO Auto-generated method stub
              switch (menuItem.getItemId()) {
                  case R.id.menu_admin_add:
  
                      for (User newAdmin : adminToAdd) {
                          DatabaseReference admin_node= FirebaseDatabase.getInstance().getReference().getRoot().child("Admins");
                          admin_node.push().setValue(idAdminToAdd);
                          Toast.makeText(UsersList.this,getString(R.string.admin_added),Toast.LENGTH_LONG).show();
                      }
                      uAdapter.notifyDataSetChanged();
                      mode.finish();
              }
              return false;
          }
  </code></pre>
  
  <p>No way, i can selelect whatever element of the listview, but i get always the first one. Any help will be appreciated.</p>
  
  <p>Update: This is the Listener i use for get the idAdminToAdd value:</p>
  
  <pre><code>DatabaseReference adminDatabase = FirebaseDatabase.getInstance().getReference().getRoot().child("Users");
      adminDatabase.addListenerForSingleValueEvent(new ValueEventListener(){
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
                  idAdminToAdd = childSnapshot.getKey();
              }
          }
          @Override
          public void onCancelled(DatabaseError databaseError) {
          }
      });
  </code></pre>