title: Android : Spinner OnSelectedItemListener
body: <p>I have an application with a ListView that displays different transactions made by the user. My code doesn't seem to work.</p>
  
  <p>The problem I have now is that I want to add a Spinner above this ListView to let the user choose whether the transactions should be ordered by date, amount or an own choice of an interval between two dates. </p>
  
  <p>Heres my code for just the spinner onSelectedItem: </p>
  
  <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_income, container, false);
          initializeComponents(view);
          registerListeners();
          spinnerOrderIncome = (Spinner) view.findViewById(R.id.spinnerOrderIncome);
          ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this.getActivity(), R.array.spinnerSortIncome, android.R.layout.simple_spinner_item);
          adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
          spinnerOrderIncome.setAdapter(adapter);
          spinnerOrderIncome.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
              @Override
              public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  switch (spinnerOrderIncome.getSelectedItem().toString()) {
                      case "date":
                          lvIncome.setAdapter(new CustomIncomeListAdapter(activity, dbController.getDataFromIncomeTable()));
                          break;
                      case "amount":
                          lvIncome.setAdapter(new CustomIncomeListAdapter(activity, dbController.getSortedAmountFromIncomeTable()));
                          break;
                  }
              }
  
              @Override
              public void onNothingSelected(AdapterView&lt;?&gt; parent) {
              }
          });
  </code></pre>
  
  <p>The ListView is already populated with this method that gets the list from the DatabaseController: </p>
  
  <pre><code>public void populateListView() {
          lvIncome.setAdapter(new CustomIncomeListAdapter(activity, dbController.getDataFromIncomeTable()));
      }
  </code></pre>
  
  <p>The methods are seen in the switch-statement where thought to change the order of the ListView, but nothing happens when I select the different spinner items (date, amount) Am I on the right track? Help! </p>