<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="horizontal">
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
-
val supportMapFragment = map as SupportMapFragment
supportMapFragment.getMapAsync { this }
我究竟做错了什么。不调用回调。 this
显示错误The expression is unused
简而言之,这样反编译,垃圾结果
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(2131296283);
Fragment var10000 = this.getSupportFragmentManager().findFragmentById(id.map);
if(var10000 == null) {
throw new TypeCastException("null cannot be cast to non-null type com.google.android.gms.maps.SupportMapFragment");
} else {
SupportMapFragment supportMapFragment = (SupportMapFragment)var10000;
supportMapFragment.getMapAsync((OnMapReadyCallback)(new OnMapReadyCallback() {
public final void onMapReady(GoogleMap it) {
MapsActivity var10000 = MapsActivity.this;
}
}));
}
}
为什么要创建 Android Studionew OnMapReadyCallback
我已经创建了它并添加了这个......
Kotlin 中的大括号只是创建一个回调。也就是说,构造的
{ this }
意思是“创建一个回调,当被调用时,它将接收这个并且不做任何事情”(因此是警告)。如果你有这个 - 这已经是所需的回调,那么你需要在括号中传递它而不是花括号:
或者代替这个,您可以编写应该执行的代码: