Android - spinners inside a ListView

邮差的信 提交于 2019-12-11 12:57:56

问题


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: (...)


回答1:


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.



来源:https://stackoverflow.com/questions/4656667/android-spinners-inside-a-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!