gpt4 book ai didi

android - startActivity 非法启动类型

转载 作者:行者123 更新时间:2023-11-29 18:45:45 24 4
gpt4 key购买 nike

截至今天上午,我已经尝试整合足够的知识来制作一个非常基本的应用程序来演示一个概念。这个想法是显示谷歌地图,用户按下他们想要添加标记的位置,然后弹出一个屏幕,他们可以在其中填写更多信息,然后当有人点击该标记时显示这些信息。

这是我从 Android Studio base 得到的。

 public class MapsActivity extends FragmentActivity implements 

OnMapReadyCallback {

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);
}

private void setMapLongClick(final GoogleMap map) {
map.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latLng) {
}
});
}

/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.z
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

// Move the camera to Delft
LatLng delft = new LatLng(52.003569, 4.372987);
Float zoom = 15f;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(delft, zoom));
setMapLongClick(mMap);
}
}

我试过添加这个

    private void setMarkerClick(final GoogleMap map) {
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
Intent intent = new Intent(this, MainActivity.class);
this.startActivity(intent);
});
}

但是我得到了“类型的非法开始”错误。我这样做完全错了吗?
有没有更简单的方法向标记添加信息?

最佳答案

这就是您应该如何使用它。

map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

@Override
public boolean onMarkerClick(Marker marker) {
Intent intent = new Intent(MainActivity.this, MainActivity.class);
startActivity(intent);
return true;
}
});

关于android - startActivity 非法启动类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52026273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com