0

I am working on google maps api, in which on map screen i want to give an option for a user to select map type through spinner. The return type of map option is integer so i am giving that value to spinner for selection through Integer Array. My code snippet is given below:

private GoogleMap mMap;

    int normMap = mMap.MAP_TYPE_NORMAL;
    int satelliteMap =mMap.MAP_TYPE_SATELLITE;
    int terrainMap =mMap.MAP_TYPE_TERRAIN; 
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.my_location_demo);
        spinnerOsversions = (Spinner) findViewById(R.id.spinner1);

        ArrayAdapter<Integer> adapter_state = new ArrayAdapter<Integer>(this,
            android.R.layout.simple_spinner_item, mapOptions);
    //Here it shows an error that Integer should not be passed to it,  want to send my mapType int array list to it   

          adapter_state.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

          spinnerOsversions.setAdapter(adapter_state);
          spinnerOsversions.setOnItemSelectedListener(this);

    }
Usman Khan
  • 3,052
  • 4
  • 30
  • 76

1 Answers1

1

Assuming Class name for the variable mapOptions is YourClass, modify your code to:

ArrayAdapter<YourClass> adapter_state = new ArrayAdapter<YourClass>(this,
        android.R.layout.simple_spinner_item, mapOptions);

In the android docs:
public ArrayAdapter (Context context, int resource, T[] objects)
Constructor Parameters
context - The current context.
resource - The resource ID for a layout file containing a TextView to use when instantiating views.
objects - The objects to represent in the ListView.

Mohammed Ali
  • 2,625
  • 4
  • 19
  • 41
  • is for my Activity class? On which i am implementing my spinner code? – Usman Khan Nov 11 '14 at 14:47
  • Whats the class name for mapOptions..? and show me where you initiliazed mapOptions.. – Mohammed Ali Nov 11 '14 at 14:49
  • i am just taking GoogleMap object and through this i am implementing mMap for my Map Options. It is a built-in method from Google API. I am just passing data comming from mMap to my defined Integers and from there i am going to make an integer array list to display in spinner. – Usman Khan Nov 11 '14 at 14:52
  • private GoogleMap mMap; int normMap = mMap.MAP_TYPE_NORMAL; int satelliteMap =mMap.MAP_TYPE_SATELLITE; int terrainMap =mMap.MAP_TYPE_TERRAIN; private int[] mapOptions = { normMap,satelliteMap,terrainMap }; – Usman Khan Nov 11 '14 at 14:54
  • try changing to ArrayAdapter – Mohammed Ali Nov 11 '14 at 14:56
  • see this for custom base adapter implementation...:http://stackoverflow.com/questions/18348123/how-to-add-data-to-custom-baseadapter-for-listview-android and also this:http://stackoverflow.com/questions/16333754/how-to-customize-listview-using-baseadapter – Mohammed Ali Nov 11 '14 at 17:42