0

I have connected my android app with firebase realtime database. It successfully retrieves data from the database and project through an activity, which is RecyclerView showing a CardView Layout. Now, when I select a specific CARD a DIALOG should pop up showing all the data of that specific firebase node only to the dialog layout.

I need to get the pushID (as 'selectedKey' variable) of that selected CARD and call the Dialog, which shows the data from firebase by retrieving again from the database with that 'KEY' string... Or is there any other simple way...?

I have also illustrated what I want to do.

connected firebase database showing the node

app activity and dialog layout

code - holder

<holder.setItemClickListener(new ItemClickListener() {
                @Override
                public void onClick(View view, int position) {
                    selectedArticle = model;
                    selectedKey = getSnapshots().getSnapshot(position).getKey();

                    Log.d("Key item", ""+selectedKey);

                    showArticle.setContentView(R.layout.show_article_dialog);

                    show_article_title.setText(model.getTitle());
                    show_article_tag1.setText(model.getTag1());
                    show_article_tag2.setText(model.getTag2());
                    show_article_tag3.setText(model.getTag3());
                    show_article_content.setText(model.getContent());

                    articleBack.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            showArticle.dismiss();
                        }
                    });
                    showArticle.show();>

1 Answers1

0

try this code to get particular node data using selected node key

 DatabaseReference mArticalReference;

mArticalReference=FirebaseDatabase.getInstance().getReference().child("ARTICALE");

String selectedKey="-Lt0JLmniHevNn4JNP57" //replace with your selected key 

mArticalReference.child(selectedKey)addListenerForSingleValueEvent(new 
 ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {

            Map<String, String> map = (Map) dataSnapshot.getValue();
            if (map != null) {
                String message = map.get("content");
                String userName = map.get("tag1");
            }

    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
    }
});
Android Geek
  • 8,956
  • 2
  • 21
  • 35
  • Thanks for the suggestion. But, the 'selected key' can't be fixed. I mean when a card is picked the 'selected key' is changed according to the selected items' position. – Salman Farshi Nov 09 '19 at 00:47
  • By the way, as the dialog isn't working for me I jumped using pop-up activity; fortunately it works now! – Salman Farshi Nov 09 '19 at 00:48