tv1,tv2,tv3,tv4始终为null。我尝试了上面的textviews定义。但没有运行。
我对layoutinflater使用错误吗?
正在运行“ Listeler temizlenemedi”错误。
但是tv1,2,3,4无法使用setText()方法。
-这不是全部代码-

 public class MapsActivity extends FragmentActivity implements OnMapReadyCallback{
      private GoogleMap myMap;
        TextView tv1,tv2,tv3,tv4;
     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_maps);
            getHandleOnMap();
     }
    private void listeyidoldur() {
            try {
                tv1.setText(" ");
                tv2.setText(" ");
                tv3.setText(" ");
                tv4.setText(" ");
            }catch (Exception ex){
                Toast.makeText(getApplicationContext(),"Listeler temizlenemedi",Toast.LENGTH_SHORT).show();
            }
            StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);

           }
                else{

                   Toast.makeText(getApplicationContext(),"internet bağlantısı gerekli",Toast.LENGTH_SHORT).show();
               }

            }catch (Exception ex){
                Log.e("xml parse hatası" , ex.getMessage().toString());
            }finally {
                if (baglanti!=null){
                baglanti.disconnect();
                 }
            }
            }

        private void getHandleOnMap()
        {
            SupportMapFragment mapFragment = (SupportMapFragment) this.getSupportFragmentManager()
                    .findFragmentById(R.id.map);
            mapFragment.getMapAsync(this);

        }
        @Override
        public void onMapReady(GoogleMap myMap) {
            //maps.....
            myMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter(){


                @Override
                public View getInfoWindow(Marker marker) {
                    View v=getLayoutInflater().inflate(R.layout.infowindows,null);
                    tv1=(TextView)findViewById(R.id.tv1);
                    tv2=(TextView)findViewById(R.id.tv2);
                    tv3=(TextView)findViewById(R.id.tv3);
                    tv4=(TextView)findViewById(R.id.tv4);
                    listeyidoldur();
                    return  v;
                }

                @Override
                public View getInfoContents(Marker marker) {
                    return null;
                }
            });

        }
    }

最佳答案

将您的初始化更改为这样。

                @Override
                public View getInfoWindow(Marker marker) {
                    View v=getLayoutInflater().inflate(R.layout.infowindows,null);
                    tv1=(TextView)v.findViewById(R.id.tv1);
                    tv2=(TextView)v.findViewById(R.id.tv2);
                    tv3=(TextView)v.findViewById(R.id.tv3);
                    tv4=(TextView)v.findViewById(R.id.tv4);
                    listeyidoldur();
                    return  v;
                }

07-26 03:11