不得显示空字段...!

Null field must not be display...!


我正在开发地图应用,
在我的应用程序中,我显示完整地址
但我只有一个问题。
如果地址字段未获取任何数据,则该字段将不会显示。
我该如何解决这个问题?
必要的代码如下
ActivityMain.java

String zip = addresses.get(0).getPostalCode();
                String city = addresses.get(0).getLocality();
                String state = addresses.get(0).getAdminArea(); 
                String country = addresses.get(0).getCountryName();

//              if (city.trim().isEmpty()) {
//                  
//              } else if (state.trim().isEmpty()) {
//                  
//              } else if (zip.trim().isEmpty()) {
//                  
//              } else if (country.trim().isEmpty()) {
//                  
//              } else {
//
//              }

                String title = zip + "," + city + "," + state + "," + country;
                showPosition.setText(zip + "\n" + city + "\n" + state + "\n" + country);
                googleMap.addMarker(new MarkerOptions().position(arg0).title(title));

showPosition 是TextView? 您应该设置 "visibility" 属性(showPosition.setVisibility(View.GONE 或 INVISIBLE)。

您应该重新格式化将在 TextView 中显示的字符串。

String title = "";
if(zip != null && zip.trim().length()>0) {
   title += zip + "\n"
}

// Same for the other fields (without else)
if(country != null && country.trim().length()>0) {
   title += country + "\n"
}

试试这个
String title = ""+zip + "," + city + "," + state + "," + country; showPosition.setText(""+zip + "\n" + 城市 + "\n" + 州 + "\n" + 国家);