Retrieving the Firebase key from onItemClick in FirebaseListAdapter

前端 未结 1 1873
挽巷
挽巷 2020-12-02 03:01

I have a Firebase DB which I\'m using the push() method to add entries to DB, thus generating the random key as a reference for each entry.

In part of t

相关标签:
1条回答
  • 2020-12-02 03:16

    You say you have a FirebaseListAdapter. If that is the case, you can get a reference to a specific item at a position with adapter.getRef().

    myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            DatabaseReference itemRef = adapter.getRef(position);
    
            Toast toast = Toast.makeText(getActivity().getApplicationContext(), itemRef.getKey(), Toast.LENGTH_SHORT);
            toast.show();
        }
    });
    
    0 讨论(0)
提交回复
热议问题