title: How to fetch data from firebase and put inside spinner
body: <blockquote>
  <p>I was trying to fetch data from firebase and put it inside a spinner, I just want name of the nodes to be displayed on the spinner drop-down , But the entire branch of node is displaying as a single item in drop down.
  Please help me to fix this
  Let me show you my Java code</p>
  </blockquote>
  <pre><code>package com.example.presence;
  
  import androidx.annotation.NonNull;
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.os.Bundle;
  import android.widget.ArrayAdapter;
  import android.widget.Spinner;
  
  import com.google.firebase.database.DataSnapshot;
  import com.google.firebase.database.DatabaseError;
  import com.google.firebase.database.DatabaseReference;
  import com.google.firebase.database.FirebaseDatabase;
  import com.google.firebase.database.ValueEventListener;
  
  import java.util.ArrayList;
  
  public class add_Attendance_Activity extends AppCompatActivity {
      Spinner spinner;
      ArrayList&lt;String&gt; list;
      ArrayAdapter&lt;String&gt; adapter;
      DatabaseReference href;
      ValueEventListener listener;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_add_attendance);
          href= FirebaseDatabase.getInstance().getReference(&quot;students&quot;);
          spinner=findViewById(R.id.spinner);
          list=new ArrayList&lt;String&gt;();
          adapter=new ArrayAdapter&lt;&gt;(this,R.layout.support_simple_spinner_dropdown_item,list);
          spinner.setAdapter(adapter);
          list.clear();
          fetchData();
          adapter.notifyDataSetChanged();
      }
      public void fetchData(){
          listener=href.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot snapshot) {
                  for(DataSnapshot mydata: snapshot.getChildren()) {
                      list.add(mydata.getValue().toString());
                  }
                  adapter.notifyDataSetChanged();
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError error) {
  
              }
          });
      }
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/JsmAT.jpg" rel="nofollow noreferrer">Spinner Looks like this</a></p>