1
votes

I searched now for two days for a solution, but i didnt find something that work.

I have a TabHost with 4 tabs and change can change the view from the first tab to another where i have a spinner. This spinner get initialized correct, but I'm not able to click on it, cause if I do I get an BadTokenException

07-28 13:52:59.446: E/AndroidRuntime(692): android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@405496d8 is not valid; is your activity running?

Now to Code:

viewToLoad = LayoutInflater.from(this).inflate(R.layout.projekt_daten, null);
        this.setContentView(viewToLoad);

To understand some Variables my function call

fuelleSpinner("SELECT _id, name FROM kunden", R.id.s_kundenauswahl);

So i fill the spinner:

private void fuelleSpinner(String selection, int spinnerID){

    Cursor spinnerCursor = mDatenbank.rawQuery(selection, null);
    spinner = (Spinner) findViewById(spinnerID);
    String[] data = new String[spinnerCursor.getCount()];

    for(int i = 0; i  adapter = 
        new ArrayAdapter(getParent(), android.R.layout.simple_spinner_item, data);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
}

I also tried this:

ArrayAdapter adapter = ArrayAdapter.createFromResource(
                getParent(), R.array.array_name, android.R.layout.simple_spinner_item);

Both ways initialize the spinner correctly, but if i click on the spinner the app crashes.

1
It didnt work, same error as beforeIgni

1 Answers

0
votes

Try this code.

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.XXXX, null);
        this.setContentView(viewToLoad);