I have a spinner that i fill with 4 elements. During startup onItemSelected method gets executed correctly and the toast message is displayed. However when i open the spinner and try to click any item, no event is called and the spinner popup will not close unless i press the spinner arrow. In other words I can not interact with spinner items.
Below is the activity code for the spinner
<Spinner
android:id="@+id/spinner"
android:popupBackground="@color/red"
android:clickable="true"
style="@style/spinner250"/>
Below is the style for the spinner
<style name="spinner250">
<item name="android:layout_width"> 250dp </item>
<item name="android:layout_height"> match_parent </item>
<item name="android:textColor"> @color/blue </item>
<item name="android:textSize"> 12sp </item>
</style>
And this is my java code for interacting with the spinner package com.example.android.gjobat;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
import org.w3c.dom.Text;
import static android.R.attr.country;
import static android.widget.ArrayAdapter.createFromResource;
public class MainActivity extends AppCompatActivity implements OnItemSelectedListener {
public Spinner spinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final String[] items = {"Item 1", "Item 2", "Item 3", "Item 4"};
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, items);
Spinner spinner = (Spinner) findViewById(R.id.spinner);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
String item = parent.getItemAtPosition(position).toString();
// User selected item
Toast.makeText(getApplicationContext(), item + " selected!", Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent)
{
}
}