Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spinner setonitemselectedlistener is not called

I have a strange problem. I need to do something when an item from spinner is selected.

Here is my code :

language = (Spinner) findViewById(R.id.current_language_text);

ArrayAdapter adapter = new ArrayAdapter(this,
                com.Orange.R.layout.my_spinner_textview, languages);

adapter.setDropDownViewResource(com.Orange.R.layout.multiline_spinner_dropdown_item);
language.setAdapter(adapter);
language.setSelection(Integer.valueOf(language_id) - 1);
language.setOnItemSelectedListener(new OnItemSelectedListener() {
     @Override
     public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        System.out.println("position "+position);
        Toast.makeText(Settings.this, "Hello Toast",Toast.LENGTH_SHORT).show();

     }

      @Override
      public void onNothingSelected(AdapterView<?> parentView) {
                            // your code here
      }
    });

The problem is that onItemSelectedListener is not called. I put System.out.println in onItemSelected() but I don't get it in LogCat. I tried with Toast, and I get the same, it doesn't appear. Every time I select an item from spinner, in LogCat I get this warning :

Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2b1dabd0

Any idea why onItemSelectedListener is not called ?

like image 972
Gabrielle Avatar asked Nov 12 '22 20:11

Gabrielle


1 Answers

Did you add your activity in manifest.xml

<activity android:name=".YourActivity" />
like image 81
Kush Avatar answered Nov 15 '22 10:11

Kush