how to change the marker on OnItemSelected Listener of gallery in android
<p>I am trying to change the marker on OnItemSelected Listener if gallery.Actually i have a gallery showing list of items and a map showing marker of the respected items in gallery .i want to change the marker ( from blue to orange  ) when i select an item from the gallery .how can i do it.i have done changing marker on tapping it by the code in this link</p>

<p><a href="http://www.google.com/url?q=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F7038636%2Fhow-to-change-the-marker-for-the-overlay-on-tap-for-android&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNFOnFJHf-f0nTea-a3Rs5hpx4U1IQ" rel="nofollow">http://www.google.com/url?q=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F7038636%2Fhow-to-change-the-marker-for-the-overlay-on-tap-for-android&amp;sa=D&amp;sntz=1&amp;usg=AFQjCNFOnFJHf-f0nTea-a3Rs5hpx4U1IQ</a> ,but not getting how can i do the same with onItemSelected  Listener.please suggest some ways.</p>

<p>i cant provide the whole code but here is some that u can understand what i have done so far.</p>

<p>here is the overlay class:</p>

<pre><code>import java.util.ArrayList;

import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.widget.Gallery;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;


/**
 * @author Anshul
 * class is responsible for creating overlays on the map
 *
 */
public class SearchCarOverlay extends ItemizedOverlay&lt;OverlayItem&gt; {
    Context context;
    MapView map;
    Gallery mapGallery; 
    private Drawable heart = null;
    private ArrayList&lt;CustomItem&gt; aList  = null;

    public SearchCarOverlay(Cursor cursor, Context m, MapView mView,
            Gallery carGallery) {
        // super(boundCenterBottom(cursor));
        super(null);
        context             = m;
        this.map            = mView;
        this.mapGallery     = carGallery;
        aList               = new ArrayList&lt;CustomItem&gt;(); 
        addItemsToList(cursor);

        populate();

    }

    /**
     * @param cursor
     * This method will add all the point to the list.
     */
    private void addItemsToList(Cursor cursor) {
        GeoPoint point = null;
        if (cursor != null &amp;&amp; cursor.getCount() &gt; 0) {
            cursor.moveToFirst();
            do {

                int lat = (int) (cursor.getDouble(cursor
                        .getColumnIndex("Latitude")) * 1000000);
                System.out.println("checking for latitude and longitude*************"
                                + lat);
                int lng = (int) (cursor.getDouble(cursor
                        .getColumnIndex("Longitude")) * 1000000);
                point = new GeoPoint(lat, lng);
                aList.add(new CustomItem(point, "", "",
                        getMarker(R.drawable.heart_full), heart));

            } while (cursor.moveToNext());

        //  map.getController().animateTo(point);

        }

    }

    /**
     * @param resource
     * @return drawable
     * for getting the map markers
     */
    private Drawable getMarker(int resource) {
        Drawable marker = context.getResources().getDrawable(resource);

        marker.setBounds(0, 0, marker.getIntrinsicWidth(),
                marker.getIntrinsicHeight());
        boundCenter(marker);
        return (marker);
    }

    @Override
    protected CustomItem createItem(int i) {

        return aList.get(i);
    }

    @Override
    public int size() {

        return aList.size();

    }

    @Override
    protected boolean onTap(int index) {
        mapGallery.setSelection( index );
        return true;
    }

    void toggleHeart() {
        CustomItem focus = (CustomItem) getFocus();

        if (focus != null) {
            focus.toggleHeart();
        }

        map.invalidate();
    }
/*
    public ArrayList&lt; CustomItem &gt; getListOfItems(){
        return aList;

    }*/
    /**
     * releases all the objects memory 
     */
    public void cleanUp(){
        context     =   null;
         map        =   null;
         mapGallery =   null;   
         heart      =   null;
    }

}

class CustomItem extends OverlayItem {
    Drawable marker = null;
    boolean isHeart = false;
    Drawable heart = null;

    CustomItem(GeoPoint pt, String name, String snippet, Drawable marker,
            Drawable heart) {
        super(pt, name, snippet);
System.out.println(" CustomItem  CONSTRUCTOR ");
        this.marker = marker;
        this.heart = heart;
    }

    @Override
    public void setMarker(Drawable marker) {
        System.out.println(" CustomItem  setMarker ");      
    //  setState(marker, android.R.attr.state_pressed);

    }


    @Override
    public Drawable getMarker(int stateBitset) {
        Drawable result = (isHeart ? heart : marker);
        System.out.println(" CustomItem  getMarker ");
        setState(result, stateBitset);

        return (result);
    }

    void toggleHeart() {
        System.out.println(" CustomItem  toggleHeart ");
        isHeart = !isHeart;
    }


}
`
and my fragment file which contains gallery and map

    public class SearchCarsFragment extends Fragmnent implements OnItemClickListener, OnClickListener{

MapView mapView;
private Gallery carGallery;

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup v, Bundle bundle) {

        View   view    = inflater.inflate( R.layout.search_car_result, null );
        headerText     = ( TextView )view.findViewById( R.id.frag_search_result );
         carGallery    = ( Gallery )view.findViewById( R.id.car_gallery );
         mapContainer  = ( LinearLayout)view.findViewById(R.id.search_map_container );
         listOrMap     = ( Button )view.findViewById( R.id.frag_search_option );
         helpButton    = ( Button )view.findViewById( R.id.frag_search_help );

         inflaterForMap = inflater;

         InitialiseMapView();
            initialiseMapAndGallery();


        listOrMap.setOnClickListener( this );
        helpButton.setOnClickListener( this );
        return view;
    }
/**
     * used to create map view everytime we come to Searchcars fragment
     */
    private void InitialiseMapView() {

        if( mapViewFrameLayout == null ){
            mapViewFrameLayout       = ( FrameLayout )inflaterForMap.inflate( R.layout.maps, null );
            mapView =   (MapView) mapViewFrameLayout.findViewById(R.id.carhomezone);
        }else{
            mapView =   (MapView) mapViewFrameLayout.findViewById(R.id.carhomezone);
        }


    }



    /**
     * initialises the map and gallery in the screen
     */
    private void initialiseMapAndGallery() {

         dismissDialog();

         cursor = DatabaseUtil.getInstance().getSortedCarResults( Constants.SORT_BY_DEFAULT );
        if( cursor != null &amp;&amp; cursor.getCount() &gt; 0 ){
            headerText.setText("Search Results ("+cursor.getCount()+")");
        initialiseMap( cursor );
        initialiseGallery( cursor );
        }else{
            System.out.println("problem in getting the data from the database");
        }   

    }

/**
     * @param cursor
     * initialises the map for search results
     */
    private void initialiseMap(Cursor cursor) { 

        InitialiseMapView();
        mapContainer.addView( mapViewFrameLayout );
        //GeoPoint point = null ;


        searchCarOverlay = new SearchCarOverlay( cursor,SearchFragmentActivity.mContext,mapView,carGallery);
        mapView.getOverlays().add( searchCarOverlay );
        mapView.setSatellite( false );
        //mapView.setStreetView( true ); 
        MapController mc = mapView.getController();
        mapView.setBuiltInZoomControls( true );

        mc.setZoom( 16 );


        //mapContainer.addView(mapView);

        //mc.animateTo( point );





        mapView.invalidate();
    }


/**
     * @param cursor
     * initialises the gallery for search results
     */
    private void initialiseGallery(Cursor cursor) {
        carGallery.setAdapter( new CarGalleyAdapter( SearchFragmentActivity.mContext ,cursor ));
        carGallery.setOnItemClickListener( this );
        carGallery.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView&lt;?&gt; parent, View view,
                    int position, long id) {
                System.out.println(" onItem selected listenert is called"+position);            

// here i need to right the code for changinh marker onItmeselected 


            }

            @Override
            public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
                System.out.println(" onNothingSelected selected listenert is called  ");

            }
        });


    }
</code></pre>
