gpt4 book ai didi

android - Textview 在 Android 上返回 null

转载 作者:行者123 更新时间:2023-11-29 15:08:25 25 4
gpt4 key购买 nike

tv1、tv2、tv3、tv4 总是为空。我尝试上面的 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;
}

关于android - Textview 在 Android 上返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34469743/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com