Load spinner inside another

Asked

Viewed 612 times

0

I wanted to know how when selecting a spinner item, another spinner is filled with an Adapter. I tried this way:

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int posicao, long arg3) {

    ArrayAdapter<String> adapter2 
           = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, minhalista);
}

But he does not let create the Adapter, in my case it can only be in the click because I will pull from a database, and load this list. How do I play the list in spinner2, when a spiner1 item is selected?

  • Don’t let create why? Are there any mistakes? Which?

1 answer

3

In your code, you are passing the callback event as context. Pass your Activity.

@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
                           int posicao, long arg3) {

    ArrayAdapter<String> adapter2 
           = new ArrayAdapter<String>([SUA ACTIVITY AQUI].this,android.R.layout.simple_spinner_item, minhalista);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.