I would like to display two values in an drop down view of my spinner.
Currently, it only has a city name, but I would also like to add a small distance field to it.
MyCity<MyCityDistance> dataAdapter;
dataAdapter = new MyCity(this, R.layout.mycityrow, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
I have all the code for custom data adapter, exapanding my view and holder etc.
However, the item which gets show doesn’t display both the city and its distance from my current location.
It only shows what is overridden in toString() method of MyCityDistance class.
I even tried setting
dataAdapter.setDropDownViewResource(R.layout.mycityrow);
but, no success. It throws an error.
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)
What is a good example of creating your own custom setDropDownViewResource()?
Even if I comment out the setDropDownViewResource() line, I get the same error.
Note: The only effect mycityrow current is that the first element of Spinner is show as per the layout of mycityrow. However, when I click open the drop down, that layout is lost. I want the same layout during drop down selection too.
Note the below example uses the inbuilt
android.R.layout.simple_list_item_2, Unfortunately the text color will probably be the same as the background. You can simply solve this by creating your own custom view and use it in the adapter instead.Let me know if i should explain any part of it.