我只想知道如何使用从方法返回的布尔值。这是返回值的方法:
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;
}
这是我想使用这个值的方法:
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);
}
请帮助我。在此先感谢。