簡體   English   中英

如果不執行位置

[英]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()方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM