Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make On Item Selected not automatically choose the first entry
    text
    copied!<p>I have created a spinner which is automatically updated with appliance names when a person adds an appliance using an array adapter. I created an OnItemSelected method with the spinner so when one of the names in the spinner is selected, a new window appears. However the OnItemSelected is automatically selecting the first item on the list when the activity starts and so the user does not have a chance to actually make a selection until the new window appears.</p> <p>Here is the code:</p> <pre><code>public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { // TODO Auto-generated method stub startActivity(new Intent("com.lukeorpin.theappliancekeeper.APPLIANCESELECTED")); } public void onNothingSelected(AdapterView&lt;?&gt; arg0) { // TODO Auto-generated method stub </code></pre> <p>Does anyone know a way in which the first item on the list wont be automatically selected?</p> <p>Here is the code for the rest of the spinner:</p> <pre><code>ArrayAdapter&lt;String&gt; appliancenameadapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, ApplianceNames); //Sets up an array adapter containing the values of the ApplianceNames string array applianceName = (Spinner) findViewById(R.id.spinner_name); //Gives the spinner in the xml layout a variable name applianceName.setAdapter(appliancenameadapter); //Adds the contents of the array adapter into the spinner applianceName.setOnItemSelectedListener(this); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload