Charlie-Blake
Charlie-Blake

Reputation: 11050

Spinner listener being called when it should not

The Listener is getting called here when I set the selection. The problem here is, I'm setting the selection BEFORE the Listener.

How can I avoid this behavior?

Spinner spCategories = (Spinner) findViewById(R.id.spinnerCategories);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.spinner_item, this.categoryList);
spCategories.setAdapter(aa);
spCategories.setSelection(selectedA);
spCategories.setOnItemSelectedListener(oiclSpCategories);

Upvotes: 1

Views: 516

Answers (1)

amukhachov
amukhachov

Reputation: 5900

Try to register OnItemSelectedListener with post method:

spCategories.post(new Runnable() {
    public void run() {
        spCategories.setOnItemSelectedListener(oiclSpCategories);
    } 
});

Upvotes: 7

Related Questions