我无法检测到长时间点击我的手机或模拟器



当我长时间点击手机或模拟器时,我无法检测到任何东西。此外,我没有收到任何错误或Logcat消息。我目前使用的是Android Studio 3.1.3。

package com.example.gaurangadas.test;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback,GoogleMap.OnMapLongClickListener {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

@Override
public void onMapLongClick(LatLng latLng) {
Toast.makeText(this, "HELLO", Toast.LENGTH_SHORT).show();
Log.i("LONG CLICK","DETECTED");
}
}
mMap.setOnMapLongClickListener(this);

之后将其放入onMapReady((中mMap=谷歌地图;这将把你的onMapLongClick注册到mMap谷歌地图。

相关内容

  • 没有找到相关文章

最新更新