Note that there are some explanatory texts on larger screens.

plurals
  1. POExample of custom setDropDownViewResource spinner item
    text
    copied!<p>I would like to display two values in an drop down view of my spinner. </p> <p>Currently, it only has a city name, but I would also like to add a small distance field to it. </p> <pre><code> MyCity&lt;MyCityDistance&gt; dataAdapter; dataAdapter = new MyCity(this, R.layout.mycityrow, list); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); </code></pre> <p>I have all the code for custom data adapter, exapanding my view and holder etc. </p> <p>However, the item which gets show doesn't display both the city and its distance from my current location. </p> <p>It only shows what is overridden in toString() method of MyCityDistance class. </p> <p>I even tried setting</p> <p><code>dataAdapter.setDropDownViewResource(R.layout.mycityrow);</code></p> <p>but, no success. It throws an error. </p> <pre><code>04-02 11:05:22.600: E/AndroidRuntime(367): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView 04-02 11:05:22.600: E/AndroidRuntime(367): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347) 04-02 11:05:22.600: E/AndroidRuntime(367): at android.widget.ArrayAdapter.getDropDownView(ArrayAdapter.java:376) 04-02 11:05:22.600: E/AndroidRuntime(367): at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:332) </code></pre> <p>What is a good example of creating your own custom <code>setDropDownViewResource()</code>? </p> <p>Even if I comment out the <code>setDropDownViewResource()</code> line, I get the same error. </p> <p>Note: The only effect <code>mycityrow</code> current is that the first element of Spinner is show as per the layout of <code>mycityrow</code>. However, when I click open the drop down, that layout is lost. I want the same layout during drop down selection too.</p>
 

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