tv1,tv2,tv3,tv4总是得到null。我尝试上面的textviews definations但是没有运行。 我使用错误来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;
}
});
}
}
答案 0 :(得分:5)
将初始化更改为这样。
@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;
}