如何在Android

时间:2019-04-12 05:36:34

标签: android if-statement retrofit response

当一个值使用改造从服务器获取而另一个值从另一个片段获取时,我尝试使用in语句比较两个值,如果使用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();
                            }

                    }
                }

1 个答案:

答案 0 :(得分: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 }
        }