ActionBar.OnNavigationListener is deprecated

I know this was asked earlier with reference to navigation, but Developer Docs say

As another navigation mode ( or filtering )

So, what would be the replacement spinner in the action bar, which simply queries the database and updates the view depending on the option selected?

+4
source share
1 answer

This question is quite old, but I still give an answer.

When you go to the v7 support library, you need to change the listener.

public class YourActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener

Spinner Creation

Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(this); //set the listener

Implement listener methods

  @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        Snackbar.make(this.getCurrentFocus(), "OnItemSelected", Snackbar.LENGTH_LONG);
        //Your implementation here
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        Snackbar.make(this.getCurrentFocus(), "onNothingSelected", Snackbar.LENGTH_LONG);
        //Your implementation here
    }

onNothingSelected method used is not clear. You can read this article to clarify.

, .

+1

Source: https://habr.com/ru/post/1569170/


All Articles