Add animation to default marker on setOnMarkerClickListener maps api v2 android -


i developing android app, have fragment containing mapview... mapview containing markers according locations in local database.. there way animate or change colour of clicked marker? mean have done in setonmarkerclicklistener, but, when click on marker, previous marker still in same color/animation...

adding main part of code below...

string mypath = db_path + db_name;     mydatabase = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readwrite);     cursor c = mydatabase.rawquery("select * location", null);     if (c != null) {         if (c.movetofirst()) {             {                 id = c.getint(0);                 if (userprefs.getstring("locale",null)==null || userprefs.getstring("locale",null).equals("en"))                 {                     storename = c.getstring(1);                 }                 else {                     storename = c.getstring(7);                 }                 stlatitude = c.getdouble(2);                 stlongitude = c.getdouble(3);                 city = c.getstring(4);                 string emirate = c.getstring(5);                 storeloc = new location("storelocation");                 storeloc.setlatitude(stlatitude);                 storeloc.setlongitude(stlongitude);                 addmarker();             }             while (c.movetonext());         }     }     mydatabase.close();      map.setonmarkerclicklistener(new googlemap.onmarkerclicklistener() {         @override         public boolean onmarkerclick(marker marker) {             string s= marker.gettitle();             string snippet= marker.getsnippet();             markerlat= marker.getposition().latitude;             markerlong= marker.getposition().longitude;             marker.seticon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_red));             tv.settext(s);             tv1.settext(snippet);                 if (s.equals(getactivity().getresources().getstring(r.string.here))) {                     if (relbutton.getvisibility() == view.visible && reltext.getvisibility() == view.visible) {                         relbutton.setalpha(1.0f);                         relbutton.animate().translationy(0).alpha(0.0f);                         relbutton.setvisibility(view.gone);                     } else if (relbutton.getvisibility() != view.visible && reltext.getvisibility() != view.visible) {                         reltext.setvisibility(view.visible);                         reltext.setalpha(0.0f);                         reltext.animate().translationy(0).alpha(1.0f);                         if (userprefs.getstring("locale",null).equals("ar"))                         {                             relativelayout relativelayout = (relativelayout) view.findviewbyid(r.id.relativelayout2);                             relativelayout.setgravity(gravity.left);                             relativelayout relativelayout1 = (relativelayout) view.findviewbyid(r.id.relativelayout1);                             relativelayout1.setgravity(gravity.right);                         }                     }                  } else if (relbutton.getvisibility() != view.visible && reltext.getvisibility() != view.visible) {                     relbutton.setvisibility(view.visible);                     reltext.setvisibility(view.visible);                     reltext.setalpha(0.0f);                     reltext.animate().translationy(0).alpha(1.0f);                     relbutton.setalpha(0.0f);                     relbutton.animate().translationy(0).alpha(1.0f);                     if (userprefs.getstring("locale",null).equals("ar"))                     {                         relativelayout relativelayout = (relativelayout) view.findviewbyid(r.id.relativelayout2);                         relativelayout.setgravity(gravity.left);                         relativelayout relativelayout1 = (relativelayout) view.findviewbyid(r.id.relativelayout1);                         relativelayout1.setgravity(gravity.right);                     }                 } else if (reltext.getvisibility() == view.visible) {                     relbutton.setvisibility(view.visible);                     relbutton.setalpha(0.0f);                     relbutton.animate().translationy(0).alpha(1.0f);                     if (userprefs.getstring("locale",null).equals("ar"))                     {                         relativelayout relativelayout = (relativelayout) view.findviewbyid(r.id.relativelayout2);                         relativelayout.setgravity(gravity.left);                         relativelayout relativelayout1 = (relativelayout) view.findviewbyid(r.id.relativelayout1);                         relativelayout1.setgravity(gravity.right);                     }                 }             return true;         }      });       directions.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             nwlocation = applocationservice.getlocation(locationmanager.network_provider);             if(nwlocation!=null) {                 userlatitude = nwlocation.getlatitude();                 userlongitude = nwlocation.getlongitude();             if(markerlat!=null && markerlong!=null) {                 string uri = "http://maps.google.com/maps?f=d&hl=en&saddr=" + userlatitude + "," + userlongitude + "&daddr=" + markerlat + "," + markerlong;                 intent intent = new intent(android.content.intent.action_view, uri.parse(uri));                 intent.setclassname("com.google.android.apps.maps", "com.google.android.maps.mapsactivity");                 startactivity(intent);             }             }             else {                 showsettingsalert("network");             }         }     });     return  view; }  private void addmarker() {     markeroptions.position(new latlng(stlatitude, stlongitude));     markeroptions.icon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.hue_violet));     markeroptions.title(getactivity().getresources().getstring(r.string.xpressionsstyle));     markeroptions.snippet(storename);     map.addmarker(markeroptions); } 

you can create arraylist different colors name in oncreateview use these lines..

and maintain value of integer int color_value =0; , increment these value on marker click event;

int color_value = 0; arraylist<string> colours = new arraylist<string>(); colours.add("hue_red"); colours.add("hue_black"); colours.add("hue_blue"); colours.add("hue_pink"); colours.add("hue_gray"); colours.add("hue_yellow"); . . . . . colours.add("hue_green"); 

and onmarkerclicklistener use following lines of code , incremnt value of color_value;

public boolean onmarkerclick(marker marker) { for(int =0;i<=colours.size();i++)  {     if(color_value==i)    {     if(color_value==colours.size)      {       colur_value=0;      }      else      {       color_value++;//increment value of color here      }              marker.seticon(bitmapdescriptorfactory.defaultmarker(bitmapdescriptorfactory.colours.get(i)));   break;   }  } } 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -