title: How do I capture the value of a Material drop down menu selection in Java?
body: <p>I am using Material to design a form with drop down lists in android studio using Java.</p>
  <p>I want to save the selection the user makes from the drop down list to a string so I can save this to Firebase, but when I try and log the result, it says the selection is null.</p>
  <p>Does anyone know how I can capture what the user selects from this type of drop down menu? I did previously have a Spinner which worked but this doesn't seem to work in the same manner.</p>
  <p>My XML code is as follows</p>
  <pre><code> &lt;com.google.android.material.textfield.TextInputLayout
              android:id=&quot;@+id/cpdTypeLayout&quot;
              style=&quot;@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginStart=&quot;16dp&quot;
              android:layout_marginEnd=&quot;16dp&quot;
              android:hint=&quot;Activity Type&quot;&gt;
  
              &lt;AutoCompleteTextView
                  android:id=&quot;@+id/cpdType&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:inputType=&quot;none&quot; /&gt;
          &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  </code></pre>
  <p>My AddAdactivity.java code is</p>
  <pre><code>//CPD TYPE DROPDOWN MENU
      cpdTypeLayout = findViewById(R.id.cpdTypeLayout);
      cpdType = findViewById(R.id.cpdType);
  
      String[] type = new String[]{
              &quot;Formal Education Completed&quot;, &quot;Other Completed&quot;, &quot;Professional Activities&quot;, &quot;Self-Directed Learning&quot;, &quot;Work-Based Learning&quot;
      };
  
      ArrayAdapter&lt;String&gt; adapterType = new ArrayAdapter&lt;&gt;(
              AddActivity.this,
              R.layout.dropdown_item,
              type
      );
  
      cpdType.setAdapter(adapterType);
  
      cpdType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              selectedTypeResult = parent.getItemAtPosition(position).toString();
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      });
  
      Log.d(&quot;TAG&quot;, &quot;You have selected &quot; + selectedTypeResult);
  </code></pre>
  <p>EDIT: have since tried this but with no luck.</p>
  <pre><code>((AutoCompleteTextView)cpdTypeLayout.getEditText()).setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              adapterType.getItem(position);
              String typeItem = ((AutoCompleteTextView)cpdTypeLayout.getEditText()).getText().toString();
              Log.d(&quot;TAG&quot;, &quot;selected type is:&quot; + typeItem);
  
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      });
  </code></pre>