请告诉我如何在没有 的情况下在 InfoWindow 中显示文本final String,否则所有标记都将带有一个文本。我需要在 InfoWindow 中推断出大约 3-4 条不同的行。下面是截图中的一段代码。
public void onChildAdded(DataSnapshot dataSnapshot, String prevChildKey) {
if(dataSnapshot.child("latitude").getValue() != null &&
dataSnapshot.child("longitude").getValue() != null) {
double latt = dataSnapshot.child("latitude").getValue(Double.class);
double longg = dataSnapshot.child("longitude").getValue(Double.class);
LatLng newLocation = new LatLng(latt, longg);
String sname = (String) dataSnapshot.child("sname").getValue();
String text = (String) dataSnapshot.child("text").getValue();
String Number = (String) dataSnapshot.child("number").getValue();
String image = dataSnapshot.child("image").getValue(String.class);
if (image.equals("akym")) {
mMap.addMarker(new MarkerOptions()
.position(newLocation)
.title(sname)
.snippet("Номер:"+Number+"\n"+"Описание:"+text)
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.akym))
);
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View myContentView = getLayoutInflater().inflate(
R.layout.custommarker, null);
TextView tvTitle = ((TextView) myContentView
.findViewById(R.id.title));
tvTitle.setText(Number);
TextView tvSnippet = ((TextView) myContentView
.findViewById(R.id.snippet));
tvSnippet.setText(marker.getSnippet());
return myContentView;
}
});
PS我知道代码很糟糕,但我正在学习)

要访问方法的内部类中的变量,有几个选项:
您可以使变量成为全局变量(将其设置在类的主体中)并且仅更改/设置方法中的值。
您可以在方法中使用单个元素制作最终数组变量:
final String[] number = new String[1]并使用它number[0] = "Текст":tvTitle.setText(number[0])等等