Problem assigning an Arrayadapter inside an Onclick container

Asked

Viewed 39 times

0

Method:

spnCondPagamento.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List listaCondPagamento = new ArrayList<>();
for (int i = 0; i < condPagDao.getListaCondPagamento().size(); i++) {
listaCondPagamento.add(condPagDao.getListaCondPagamento().get(i).getDescricao());
listaIdCondPag.add(condPagDao.getListaCondPagamento().get(i).getId());
}
ArrayAdapter condPagAdapter = new ArrayAdapter<>(this, R.layout.support_simple_spinner_dropdown_item, listaCondPagamento);
condPagAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
spnCondPagamento.setAdapter(condPagAdapter);

        }
    });

the problem is that it is showing a erro:

Arrayadapter condPagAdapter = new Arrayadapter<>(this, R.layout.support_simple_spinner_dropdown_item, listCondPagamento);

of unchecked assignment being that if you sign it as Error string yet

  • Did you sign both left and right? (http://stackoverflow.com/a/4204999/520779)

  • 1

    I think the problem is the use of this which in this case refers to the class/interface View.Onclicklistener who does not inherit from Context. Change this for NomeDaActivity.this.

  • 1

    You are inside a method that is being overwritten, try to exchange this for 'Minhaactivity.this' try to change the context briefly and let us think of something else to help you

  • this will be the signature of Contexto, thanks to all! I switched this to Nomedaactivity.this

No answers

Browser other questions tagged

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