布尔值在另一个方法java中没有改变

时间:2017-07-18 09:19:01

标签: java android

我已将boolean hasCoverage定义为true。当它调用下一个方法时,实际代码根据所选数据将hasCoverage值设置为false或true。事情是我最初设定的价值,那只是采取。 这是我的代码:

boolean hasCoverage = true;

private void checkCoverage() {
    try {
        JSONObject[] restaurants_arr = null;
        try {
            if (response != null) {
                JSONArray restaurants = response.getJSONArray("restaurants");

                // if restaurants deliver to that area
                if (restaurants.length() > 0) {
                    restaurants_arr = new JSONObject[restaurants.length()];
                    int has_coverage = 1; // assume coverage is there..

                    for (int j = 0; j < Utils.cart_restaurants.size(); j++) {
                        RestaurantModel restaurant = Utils.cart_restaurants.get(j);
                        String restaurantCartID = restaurant.getId();
                        boolean found = false;
                        for (int i = 0; i < restaurants.length(); i++) {
                            restaurants_arr[i] = restaurants.getJSONObject(i);
                            String restaurantID = restaurants_arr[i].get("restaurant_id").toString();
                            if (restaurantCartID.equals(restaurantID)) {
                                found = true;
                                break;
                            }
                        }  //end of inner for
                        if (found == false) {
                            Toast.makeText(CheckoutActivity.this, "There is no coverage for the Selected Area ", Toast.LENGTH_SHORT).show();
                            hasCoverage = false;
                            break;
                        }
                    } //end of outer for
                } //end of if
                else { //if restaurants don't deliver to that area
                    Toast.makeText(CheckoutActivity.this, "There is no coverage for the Selected Area ", Toast.LENGTH_SHORT).show();
                    hasCoverage = false;
                }
            } // end of if response != null
        } // end of try
        catch (Exception ex) {
            GSLogger.e(ex);
            showError();
        }
    }
}

我在这里定义了。基于区域覆盖率,布尔值正在变化。现在,我想将此方法中收到的值传递给下一个方法。 这是代码:

checkout_btn.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        city_id = addressObj.getCity().getId();
        if (Utils.isLoggedIn) {
            checkCoverage();
            if (hasCoverage) { // hasCoverage takes initialized value which is difened at the beginning
                processOrder();
            }
            else {
                Toast.makeText(CheckoutActivity.this, "There is no coverage for the Selected Area ", Toast.LENGTH_SHORT).show();
            }
        }
    }
});

0 个答案:

没有答案