title: Custom InfoWindow for particular markers
body: <p>I'm working on cab booking app where I use different type of markers(one for passenger and many for the cabs ) for the passenger marker I don't need a custom InfoWindow , but for the cabs'( where I show different information about them that can possibaly change) I do,therefore I've customed an InfoWindow one using a resource layout file (info_window.xml), but whatever I've tried (even using hideInfoWindow(); ) I couldn't hide the passenger's InfoWindow, also whenever I try to set Text to an InfoWindow TextView the app cruches ,If what I'm trying to  is possible then what I'm doing wrong ? If it is not, is there an other way to show information without using InfoWindows , something similar to this perhaps !
  <a href="https://i.stack.imgur.com/aVYjF.png" rel="nofollow noreferrer">enter image description here</a> knowing that the InfoWindow have been converted to Bitmap I tried also to use Simple information balloon annotation for Android MapView as in this link <a href="https://github.com/jgilfelt/android-mapviewballoons" rel="nofollow noreferrer">https://github.com/jgilfelt/android-mapviewballoons</a> but it's deprecated ,What should I use instead !!
  Ps:I need to have a clickable button on it.</p>
  
  <p>this is <strong>info_window.xml</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:orientation="vertical" android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:weightSum="1"&gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/tvLatitude"
          android:text="Latitude"
          android:layout_marginRight="15dp"
           /&gt;
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/tvLongitude"
          android:text="Longitude"
          android:layout_marginRight="10dp"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and those are parts from <strong>MapActivity.java</strong></p>
  
  <pre><code>public class MapActivity extends AppCompatActivity implements OnMapReadyCallback {
  private BroadcastReceiver broadcastReceiver;
  GoogleMap map;
  static Double latt, lngg;
  private String[] perms = {"android.permission.ACCESS_COARSE_LOCATION",
          "android.permission.ACCESS_FINE_LOCATION",
          "android.permission.INTERNET"};
  HashMap&lt;Integer, Marker&gt; markerMap = new HashMap&lt;Integer, Marker&gt;();
  Marker marker;
  
   @Override
   protected void onResume() {
      super.onResume();
      if(broadcastReceiver == null){
          broadcastReceiver = new BroadcastReceiver() {
              @Override
              public void onReceive(Context context, Intent intent) {
                  getJSON();
                  lngg= intent.getDoubleExtra("longitude",-1);
                  latt= intent.getDoubleExtra("latitude",-1);
  
                  Marker m =map.addMarker(new MarkerOptions()
                          .position(new LatLng(latt,lngg))
                          .icon(BitmapDescriptorFactory.fromResource(R.drawable.icon2))
                          .title("I'm a passenger"));
                       m.hideInfoWindow();
                //  goToLocationZoom(latt, lngg , 15) ;
  
  
              }
          };
      }
      registerReceiver(broadcastReceiver, new IntentFilter("location_update"));
  
  
  }
  
  
  class BackgroundTask extends AsyncTask&lt;Void,Void,String&gt;{
      String JSON_STRING;
      String json_url ;
      @Override
      protected void onPreExecute() {
  
          json_url="http://frequentative-hicko.000webhostapp.com/FetchLocAndId.php";
      }
  
      @Override
      protected String doInBackground(Void... voids) {
  
          try {
              URL url = new URL(json_url);
              HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
              InputStream inputStream = httpURLConnection.getInputStream();
              BufferedReader bufferedReader= new BufferedReader( new InputStreamReader(inputStream));
              StringBuilder stringBuilder= new StringBuilder();
              while( (JSON_STRING = bufferedReader.readLine()) != null ){
  
                  stringBuilder.append(JSON_STRING+"\n");
              }
              bufferedReader.close();
              inputStream.close();
              httpURLConnection.disconnect();
              return stringBuilder.toString().trim();
  
  
  
  
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return null;
      }
  
      @Override
      protected void onProgressUpdate(Void... values) {
          super.onProgressUpdate(values);
      }
  
      @Override
      protected void onPostExecute(String response) {
          TextView textView =(TextView) findViewById(R.id.textView2);
        //  textView.setText(response); //JSON Format
  
          // System.out.println("json_string="+json_string);
          if(response== null){
  
              Toast.makeText(getApplicationContext(),response,Toast.LENGTH_LONG);
  
          }
          else {
  
              try {
                  JSONObject jsonObject = new JSONObject(response);
                  JSONArray jsonArray = jsonObject.getJSONArray("response");
                  int i=0 ;
                  int id,e;
                  Double lt,lg;
                  while (i&lt;jsonArray.length()) {
                      JSONObject jo = jsonArray.getJSONObject(i);
                      e=  jo.getInt("etat");
  
                      id= jo.getInt("driver_id");
  
                      lt=jo.getDouble("latitude");
  
                      lg= jo.getDouble("longitude");
  
                       if(e==0){
                           marker = markerMap.get(id);
                           if(marker != null){
                               marker.remove();
                               markerMap.remove(id);
                           }else
                           {
                               markerMap.remove(id);
                           }
                       }else{
   map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
  
                               // Use default InfoWindow frame
                               @Override
                               public View getInfoWindow(Marker arg0) {
  
  
                         return null;
                               }
  
                               // Defines the contents of the InfoWindow
                               @Override
                               public View getInfoContents(Marker arg0) {
  
                                   // Getting view from the layout file info_window_layout
                                   View v = getLayoutInflater().inflate(R.layout.info_window, null);
  
                                   // Getting the position from the marker
                                   TextView tvLatitude= (TextView) findViewById(R.id.tvLatitude);
                                  tvLatitude.setText("Latitude ");
                                   // Returning the view containing InfoWindow contents
                                   return v;
  
                               }
                           });
                           if (markerMap.containsKey(id)) {
  
                      // Update the location.
                      marker = markerMap.get(id);
                      marker.remove();
                      markerMap.remove(id); //added
                      MarkerOptions markerOpt = new MarkerOptions()
                              .title("route_direct").position(new LatLng(lt,lg)).visible(true);
                      marker = map.addMarker(markerOpt);
                      markerMap.put(id, marker);
  
                      } else {
  
                          MarkerOptions markerOpt = new MarkerOptions()
                                  .title("route_direct").position(new     LatLng(lt, lg)).visible(true);
  
                          marker = map.addMarker(markerOpt);
                          markerMap.put(id, marker);
  
                      }}
  
                      i++;}
  
  
                      }catch (JSONException e) {
              e.printStackTrace();
              AlertDialog.Builder nbuilder = new AlertDialog.Builder(MapActivity.this);
              nbuilder.setMessage("Erreur")
                      .setNegativeButton("Retry", null)
                      .create()
                      .show();
              }
  
          }
  
     }
     }
     }
  </code></pre>
  
  <p>this the error I got</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
                Process: androidloginandregistration.inducesmile.com.ataxiapp, PID: 7484
                java.lang.NullPointerException
                    at androidloginandregistration.inducesmile.com.ataxiapp.MapActivity$BackgroundTask$1.getInfoWindow(MapActivity.java:331)
                    at com.google.android.gms.maps.GoogleMap$7.zzh(Unknown Source)
                    at com.google.android.gms.maps.internal.zzd$zza.onTransact(Unknown Source)
                    at android.os.Binder.transact(Binder.java:361)
                    at com.google.android.gms.maps.internal.p.a(:com.google.android.gms.DynamiteModulesB:94)
                    at com.google.maps.api.android.lib6.impl.by.a(:com.google.android.gms.DynamiteModulesB:89)
                    at com.google.maps.api.android.lib6.impl.by.a(:com.google.android.gms.DynamiteModulesB:124)
                    at com.google.maps.api.android.lib6.gmm6.api.e.a(:com.google.android.gms.DynamiteModulesB:188)
                    at com.google.maps.api.android.lib6.gmm6.api.g.c(:com.google.android.gms.DynamiteModulesB:200)
                    at com.google.maps.api.android.lib6.impl.db.g(:com.google.android.gms.DynamiteModulesB:23225)
                    at com.google.maps.api.android.lib6.impl.dd.b(:com.google.android.gms.DynamiteModulesB:304)
                    at com.google.maps.api.android.lib6.gmm6.api.e.a(:com.google.android.gms.DynamiteModulesB:242)
                    at com.google.maps.api.android.lib6.gmm6.vector.m.a(:com.google.android.gms.DynamiteModulesB:4070)
                    at com.google.maps.api.android.lib6.gmm6.vector.af.c(:com.google.android.gms.DynamiteModulesB:611)
                    at com.google.maps.api.android.lib6.gmm6.vector.df.onSingleTapConfirmed(:com.google.android.gms.DynamiteModulesB:236)
                    at com.google.maps.api.android.lib6.impl.gesture.g.onSingleTapConfirmed(:com.google.android.gms.DynamiteModulesB:189)
                    at com.google.maps.api.android.lib6.impl.gesture.i.handleMessage(:com.google.android.gms.DynamiteModulesB:132)
                    at android.os.Handler.dispatchMessage(Handler.java:102)
                    at android.os.Looper.loop(Looper.java:136)
                    at android.app.ActivityThread.main(ActivityThread.java:5476)
                    at java.lang.reflect.Method.invokeNative(Native Method)
                    at java.lang.reflect.Method.invoke(Method.java:515)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
                    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>