I just want to know how to use a boolean value returned from a method.This is the method which is returning the value:
public boolean hasConnection() { ConnectivityManager cm = (ConnectivityManager) MCQ.this.getBaseContext().getSystemService( Context.CONNECTIVITY_SERVICE); NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (wifiNetwork != null && wifiNetwork.isConnectedOrConnecting()) { return true; } NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (mobileNetwork != null && mobileNetwork.isConnectedOrConnecting()) { return true; } NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (activeNetwork != null && activeNetwork.isConnectedOrConnecting()) { return true; } return false; } This is the method where i want to use this value:
public void setScrollViewLayoutMarginBottom() { Resources resources = this.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); Boolean b = hasConnection(); if(b == true) { px = 90 * (metrics.densityDpi/160f); } else px = 60 * (metrics.densityDpi/160f); layoutParams.bottomMargin = (int) px; layoutParams.setMargins(0, 0, 0, (int) px); sv.setLayoutParams(layoutParams); } Please help me.Thanks in advance.
Booleanby just doingif(hasConnection()), but otherwise, I don't see a problem.boolean, and notBoolean. There's no reason to transform the primitive value into an object. And if(b == true)is ugly. Just useif (b).