5

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 ?

4

2 に答える 2

1

manifest.xml にアクティビティを追加しましたか

<activity android:name=".YourActivity" />
于 2016-06-23T06:01:17.780 に答える
0

このようなものを追加します。

   example=spinnerdistrics.getItemAtPosition(position).toString();
于 2016-06-23T05:24:09.083 に答える