你如何停用,例如if (mGoogleApiClient == null && checkGooglePlayService()) {
Log.d(Utils.TAG_DEV + TAG, "Building GoogleApiClient");
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
mLocationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(mLocationRequest);
builder.setAlwaysShow(true);
mLocationSettingsRequest = builder.build();
PendingResult<LocationSettingsResult> result =
LocationServices.SettingsApi.checkLocationSettings(
mGoogleApiClient,
mLocationSettingsRequest
);
result.setResultCallback(this);
}
组件上的mouseReleased事件回调?
答案 0 :(得分:1)
您可以使用enabled属性覆盖JSlider。添加鼠标侦听器时,请创建一个新的鼠标侦听器,该侦听器委派给原始侦听器,但仅在启用该属性时才启用:
import javax.swing.JSlider;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
class MyJSlider extends JSlider
{
private boolean isEnabled = true;
public void setEnabled(boolean isEnabled)
{
this.isEnabled = isEnabled;
}
@Override
public synchronized void addMouseListener(final MouseListener delegate)
{
super.addMouseListener(
new MouseListener() {
@Override
public void mouseClicked(final MouseEvent e) {
delegate.mouseClicked(e);
}
@Override
public void mousePressed(final MouseEvent e) {
delegate.mousePressed(e);
}
@Override
public void mouseReleased(final MouseEvent e) {
if (isEnabled) {
delegate.mouseReleased(e);
}
}
@Override
public void mouseEntered(final MouseEvent e) {
delegate.mouseEntered(e);
}
@Override
public void mouseExited(final MouseEvent e) {
delegate.mouseExited(e);
}
}
);
}
}
答案 1 :(得分:0)
我通常只是在对类中的本地布尔标志进行检查,然后在处理我打开或关闭的监听器的其余部分之前添加它,以确定是否应该处理监听器。