如果不使用位置执行
If not executing with location
我有一个 if 语句来检查以确保邮政编码与我们服务的区域相匹配,但是当我在邮政编码中时,我正在测试 If 不 运行。请告诉我我做错了什么
String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName();
// final TextView mTextView = (TextView) findViewById(R.id.location);
//mTextView.setText("Latitude "+latitude+" Longitude "+longitude);
final TextView mAdressTextView = (TextView) findViewById(R.id.addressNum);
mAdressTextView.setText(address);
final TextView mStateTextView = (TextView) findViewById(R.id.stateNum);
mStateTextView.setText(city+ ", "+ state+", " + postalCode);
if (postalCode == "33331"){
Intent logoutDone = new Intent(MainActivity.this, Register.class);
startActivity(logoutDone);
Log.d("ADebugTag", "Value: " + postalCode);
}
我不确定你所说的 if 不 运行 是什么意思,但这个答案可能会有所帮助。
在Java中,== 比较对象的引用。您的目标是查看 postalCode 字符串对象是否包含“33331”。所以你想这样做:
if(postalCode.equals("33331"))
{
// do stuff
}
如果您想查看两个对象是否是同一个实例,您可以使用 == 代替。当你想比较两个字符串的值时,需要像我上面那样使用equals()方法
我有一个 if 语句来检查以确保邮政编码与我们服务的区域相匹配,但是当我在邮政编码中时,我正在测试 If 不 运行。请告诉我我做错了什么
String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName();
// final TextView mTextView = (TextView) findViewById(R.id.location);
//mTextView.setText("Latitude "+latitude+" Longitude "+longitude);
final TextView mAdressTextView = (TextView) findViewById(R.id.addressNum);
mAdressTextView.setText(address);
final TextView mStateTextView = (TextView) findViewById(R.id.stateNum);
mStateTextView.setText(city+ ", "+ state+", " + postalCode);
if (postalCode == "33331"){
Intent logoutDone = new Intent(MainActivity.this, Register.class);
startActivity(logoutDone);
Log.d("ADebugTag", "Value: " + postalCode);
}
我不确定你所说的 if 不 运行 是什么意思,但这个答案可能会有所帮助。
在Java中,== 比较对象的引用。您的目标是查看 postalCode 字符串对象是否包含“33331”。所以你想这样做:
if(postalCode.equals("33331"))
{
// do stuff
}
如果您想查看两个对象是否是同一个实例,您可以使用 == 代替。当你想比较两个字符串的值时,需要像我上面那样使用equals()方法