title: Android Studio: ListView and Firebase Variable Value
body: <p>Asking another question here.</p>
  <p>On my register page within the app, the EditTexts work fine at sending the text input by the user to the Realtime Database. However, I would like to know how to create 2 spinners for Year and Courses. The user should be able to select their study year and course and have it updated to the database, however I'm not sure how to get the value from the Spinner into the year and course variable within the User class for the database. I know String arrays are typically used within the Strings.xml so those are there.</p>
  <pre><code>&lt;string-array name=&quot;Years&quot;&gt;
          &lt;item&gt;UG 1st Year&lt;/item&gt;
          &lt;item&gt;UG 2nd Year&lt;/item&gt;
          &lt;item&gt;UG 3rd Year&lt;/item&gt;
          &lt;item&gt;UG 4th Year&lt;/item&gt;
          &lt;item&gt;PG 1st Year&lt;/item&gt;
          &lt;item&gt;PG 2nd Year&lt;/item&gt;
          &lt;item&gt;PG 3rd Year&lt;/item&gt;
          &lt;item&gt;PG 4th Year&lt;/item&gt;        
      &lt;/string-array&gt;
      
      &lt;string-array name=&quot;Courses&quot;&gt;
          &lt;item&gt;Accounting&lt;/item&gt;
          &lt;item&gt;Computer Science&lt;/item&gt;
          &lt;item&gt;Economics&lt;/item&gt;
          &lt;item&gt;Health Care&lt;/item&gt;
          &lt;item&gt;Journalism&lt;/item&gt;
          &lt;item&gt;Medicine&lt;/item&gt;
          &lt;item&gt;Technology&lt;/item&gt;
      &lt;/string-array&gt;
  </code></pre>
  <p>Any help would be appreciated, here is the Register Java class and User class.</p>
  <p>Auth Page:</p>
  <pre><code>import androidx.annotation.NonNull;
  import androidx.appcompat.app.AppCompatActivity;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Patterns;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.ProgressBar;
  import android.widget.Spinner;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.google.android.gms.tasks.OnCompleteListener;
  import com.google.android.gms.tasks.Task;
  import com.google.firebase.auth.AuthResult;
  import com.google.firebase.auth.FirebaseAuth;
  import com.google.firebase.database.FirebaseDatabase;
  
  public class AuthenticateUser extends AppCompatActivity implements View.OnClickListener {
  
      //Initializing all EditText, TextViews, Buttons, Firebase and Progress Bar.
  
      private TextView authUser, loginUser;
      private EditText editTextAuthName, editTextAuthEmail, editTextAuthPassword, editTextAuthYear, editTextAuthCourse, editTextUserRole, editTextAbsences, editTextPresent, editTextClassesAttended;
      private ProgressBar progressBar2;
  
      private FirebaseAuth mAuth;
  
      //Declaring all the EditTexts with their XML fields.
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_authenticate_user);
  
          mAuth = FirebaseAuth.getInstance();
  
          authUser = (Button) findViewById(R.id.buttonAuthUser);
          authUser.setOnClickListener(this);
  
          editTextAuthName = (EditText) findViewById(R.id.editTextAuthName);
          editTextAuthEmail = (EditText) findViewById(R.id.editTextAuthEmail);
          editTextAuthPassword = (EditText) findViewById(R.id.editTextAuthPassword);
          editTextAuthYear = (EditText) findViewById(R.id.editTextTYearOfStudy);
          editTextAuthCourse = (EditText) findViewById(R.id.editTextCourseName);
          editTextUserRole = (EditText) findViewById(R.id.editTextAuthRole);
          editTextAbsences = (EditText) findViewById(R.id.editTextAuthAbsences);
          editTextPresent = (EditText) findViewById(R.id. editTextAuthPresent);
          editTextClassesAttended = (EditText) findViewById(R.id.editTextClassesAttended);
  
          progressBar2 = (ProgressBar) findViewById(R.id.progressBar2);
  
          loginUser = (TextView) findViewById(R.id.textViewAuthLoginHere);
          loginUser.setOnClickListener(this);
  
      }
  
      //This onClick method checks runs the selected activity/method on whichever button the user clicks on.
  
      @Override
      public void onClick(View view) {
  
          switch (view.getId()) {
              case R.id.buttonAuthUser:
                  authUser();
                  break;
              case R.id.textViewAuthLoginHere:
                  startActivity(new Intent(this, MainActivity.class));
          }
  
      }
  
      //This authUser() method is the user's inputs being error checked and then uploaded to the Firebase Database.
  
      private void authUser() {
  
          String name = editTextAuthName.getText().toString();
          String email = editTextAuthEmail.getText().toString();
          String password = editTextAuthPassword.getText().toString();
          String year = editTextAuthYear.getText().toString();
          String course = editTextAuthCourse.getText().toString();
          String role = editTextUserRole.getText().toString();
          String absences = editTextAbsences.getText().toString();
          String present =  editTextPresent.getText().toString();
          String classes = editTextClassesAttended.getText().toString();
  
          if (name.isEmpty()) {
              editTextAuthName.setError(&quot;Full name is required&quot;);
              editTextAuthName.requestFocus();
              return;
          }
  
          if (email.isEmpty()) {
              editTextAuthEmail.setError(&quot;Email is required!&quot;);
              editTextAuthEmail.requestFocus();
              return;
          }
  
          if (!email.contains(&quot;@&quot;) || !email.contains(&quot;.ac.uk&quot;)) {
              editTextAuthEmail.setError(&quot;Please enter a valid Academic Email address (Institution.ac.uk)&quot;);
              editTextAuthEmail.requestFocus();
              return;
          /
  
  
          if (password.isEmpty()) {
              editTextAuthPassword.setError(&quot;Password is required!&quot;);
              editTextAuthPassword.requestFocus();
              return;
          }
  
          if (year.isEmpty()) {
              editTextAuthYear.setError(&quot;Study Year is required!&quot;);
              editTextAuthYear.requestFocus();
              return;
          }
  
        
          if (course.isEmpty()) {
  
              editTextAuthCourse.setError(&quot;Course Name is Required&quot;);
              editTextAuthCourse.requestFocus();
              return;
          }
  
          //This method then uploads the inserted data to the Firebase database.
  
          progressBar2.setVisibility(View.VISIBLE);
          mAuth.createUserWithEmailAndPassword(email, password)
                  .addOnCompleteListener(new OnCompleteListener&lt;AuthResult&gt;() {
                      @Override
                      public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
  
                          if (task.isSuccessful()) {
                              User user = new User(name, email, year, course, role, absences, present, classes);
  
                              FirebaseDatabase.getInstance().getReference(&quot;Users&quot;)
                                      .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                      .setValue(user).addOnCompleteListener(new OnCompleteListener&lt;Void&gt;() {
                                  @Override
                                  public void onComplete(@NonNull Task&lt;Void&gt; task) {
  
                                      if (task.isSuccessful()) {
                                          Toast.makeText(AuthenticateUser.this, &quot;User has been authorised successfully!&quot;, Toast.LENGTH_LONG).show();
                                          progressBar2.setVisibility(View.GONE);
                                      } else {
                                          Toast.makeText(AuthenticateUser.this, &quot;Failed to Authorise, try again&quot;, Toast.LENGTH_LONG).show();
                                          progressBar2.setVisibility(View.GONE);
                                      }
                                  }
                              });
  
                          } else {
                              Toast.makeText(AuthenticateUser.this, &quot;Failed to Authorise, a user with the email &quot; + email + &quot; already exists&quot;, Toast.LENGTH_LONG).show();
                              progressBar2.setVisibility(View.GONE);
  
                          }
                      }
                  });
      }
  }
  </code></pre>
  <p>User page:</p>
  <pre><code>public class User {
  
      //Initializing all of the variable names and values for the Database to upload to and pull from.
  
      public String name, email, year, course, role, absences, present, classes;
  
  
      public User() {
  
      }
  
      public User(String name, String email, String year, String course, String role, String absences, String present, String classes) {
  
          //These will be used to upload and pull data to and from the database, mainly for the Profile.class
  
          this.name = name;
          this.email = email;
          this.year = year;
          this.course = course;
          this.role = role;
          this.absences = absences;
          this.present = present;
          this.classes = classes;
  
      }
  }
  </code></pre>
  <p>Would anyone be able to help me please, this project is due in a few weeks time and it's only this issue I'm having. Thanks!</p>