title: Get Key from Firebase Database Android
body: <p>I have firebase data as below. I want to display key in the textview when click on ListView.</p>
  
  <p><a href="https://i.stack.imgur.com/8JjJt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8JjJt.jpg" alt="enter image description here"></a></p>
  
  <p>I try to get key from discount with below code</p>
  
  <pre><code>private void getKeyValues(){
  
      databaseReference = FirebaseDatabase.getInstance().getReference().child("promotion").child("discount");
  
      databaseReference.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              String key = dataSnapshot.getKey();
  
              for (DataSnapshot child: dataSnapshot.getChildren()){
                  //Object object = child.getKey();
                  labelGetKey.setText(child.getKey());
              }
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
              Log.e("Read Fail", "Error");
          }
      });
  }
  </code></pre>
  
  <p>It's working but only get the last key and show in the textview. the first key or other key didn't show.
  here is my code for listview</p>
  
  <pre><code>private void retrieveDataShowListView(){
      // Array List and Adapter for Message ListView;
      final ArrayList&lt;String&gt; arrayList = new ArrayList&lt;&gt;();
      final ArrayAdapter&lt;String&gt; adapter;
  
      databaseReference = FirebaseDatabase.getInstance().getReference().child("promotion").child("discount");
  
      adapter = new ArrayAdapter&lt;&gt;(this,android.R.layout.simple_list_item_1,arrayList);
      listViewPromotion.setAdapter(adapter);
      listViewPromotion.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              String showValue = String.valueOf(parent.getItemAtPosition(position));
              editTextPromotion.setText(showValue);
  
              // Display Key from Database
              getKeyValues();
          }
      });
  
      databaseReference.addChildEventListener(new ChildEventListener() {
          @Override
          public void onChildAdded(DataSnapshot dataSnapshot, String s) {
              String strLocation = dataSnapshot.getValue(String.class);
              arrayList.add(strLocation);
              adapter.notifyDataSetChanged();
          }
  
          @Override
          public void onChildChanged(DataSnapshot dataSnapshot, String s) {}
  
          @Override
          public void onChildRemoved(DataSnapshot dataSnapshot) {
              String string = dataSnapshot.getValue(String.class);
              arrayList.remove(string);
              adapter.notifyDataSetChanged();
          }
  
          @Override
          public void onChildMoved(DataSnapshot dataSnapshot, String s) {}
  
          @Override
          public void onCancelled(DatabaseError databaseError) {}
      });
  }
  </code></pre>
  
  <p>Can you help me what is the mistake about my code. Thanks!</p>