Abramodj
Abramodj

Reputation: 5879

Android - spinners inside a ListView

i have a ListView with a custom Servizio object in every row. I'm using SimpleAdapter for this and it's ok.

The problem is that i can't fill the spinner inside every Servizio. This code inside Servizio.java is causing my app to crash:

Spinner spinner = (Spinner) findViewById(R.id.spinner);

        int m = 3;//Integer.parseInt(camping.rulesList.getMaxPers().get(camping.tipSel));

        String[] array_spinner=new String[m];
        for (int indice = 0; indice < m; indice++)
        {
            if (indice == 0) array_spinner[indice] = String.format("%d persona", indice+1);
            else array_spinner[indice] = String.format("%d persone", indice+1);
        }

        ArrayAdapter<String> aa = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_item, array_spinner);
        aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(aa);

The same code is working for a single spinner on the main activity... what am i missing?

Thanks! ;-)

UPDATE: Here's the Log... Maybe the problem is that "Attempted to add window with non-application token WindowToken"...

01-11 16:23:06.038: WARN/dalvikvm(12582): threadid=1: thread exiting with uncaught exception (group=0x40028a00) 01-11 16:23:06.038: WARN/WindowManager(103): Attempted to add window with non-application token WindowToken{44ac0100 token=null}. Aborting. 01-11 16:23:06.058: (...)

Upvotes: 1

Views: 2123

Answers (1)

Abramodj
Abramodj

Reputation: 5879

Ok the problem was that i was using getApplicationContext() instead of this. And it didn't work 'till i've deleted All the getApplicationContext() of the class.

Upvotes: 3

Related Questions