如何将两个值与android中的if语句进行比较

问题描述 投票:0回答:1

我试图比较两个值与if语句当一个值从服务器使用retrofit获取而另一个值从另一个片段获取,如果Toast使用外部if语句然后显示两个变量值但是如果我尝试将这些值比较为if语句它不管用。两个值都相同,但编译器转到其他部分,我做什么

public void getUserProfileData() {
    progressBar.setVisibility(View.VISIBLE);
    Api.getClient().getUserProfile(MainActivity.userId, new Callback<UserProfileResponse>() {
                @Override
                public void success(UserProfileResponse userProfileResponse, Response response) {
                    progressBar.setVisibility(View.GONE);
                    userEmail=userProfileResponse.getEmail();
                    String s = "";
                    if (!userProfileResponse.getLandmark().equalsIgnoreCase("")) {
                        s = ", " + userProfileResponse.getLandmark();
                    }
                    if (userProfileResponse.getFlat().equalsIgnoreCase("")) {
                        addressCheckBox.setChecked(false);
                        addressCheckBox.setVisibility(View.GONE);
                        fillAddress.setVisibility(View.VISIBLE);
                    }else {
                        address = userProfileResponse.getName()
                                + ", "
                                + userProfileResponse.getFlat()
                                + s
                                + ", " + userProfileResponse.getLocality()
                                + ", " + userProfileResponse.getCity()
                                + ", " + userProfileResponse.getState()
                                + ", " + userProfileResponse.getPincode()
                                + "\n" + userProfileResponse.getMobile();
                        addressCheckBox.setText(address);
                        mobileNo = userProfileResponse.getMobile();
                        pinCompare = userProfileResponse.getPincode();


                        //Toast.makeText(getActivity(), pincode + pinCompare, Toast.LENGTH_SHORT).show();



                            if(pincode.equals(pinCompare)){           //is it correct code?
                                Toast.makeText(getActivity(), "correct", Toast.LENGTH_SHORT).show();
                            }else {
                                Toast.makeText(getActivity(), "failed", Toast.LENGTH_SHORT).show();
                            }

                    }
                }
android if-statement retrofit response
1个回答
0
投票

在此代码中进行一些更改..

            if (pincode !=null && pinCompare!=null){
            if(pincode.equals(pinCompare)){           //is it correct code?
                Toast.makeText(getActivity(), "correct", Toast.LENGTH_SHORT).show();
            }else {
                Toast.makeText(getActivity(), "failed", Toast.LENGTH_SHORT).show();
            }else { //do somthing }
        }
© www.soinside.com 2019 - 2024. All rights reserved.