私はGoogle Mapsに問題があります。つまり、getSupportFragmentManager()です。findFragmentByIdは常にnullを返します。これを解決する方法がありますか?ここでgetSupportFragmentManager().FindFragmentByIdは、アンドロイドのフラグメント内のGoogleマップのnullを返しますか?
コードです:
fragment_map.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myapp.something.MapFragment">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</FrameLayout>
MapsFragment.java:
public class MapFragment extends Fragment implements OnMapReadyCallback, android.location.LocationListener
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
SupportMapFragment mapFragment = (SupportMapFragment) this.getActivity().getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
...
私が活動にGoogleマップを持っており、それがコードで動作します:
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
私がしようとしていますこれをフラグメントで再利用してください。マップではなくフラグメントでマップする必要がありますが、動作しません。
私が試した: "onCreateView" 機能では、このコードを呼び出す
SupportMapFragment mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.map);
GoogleMap mGoogleMap = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map)).getMap();
は廃止、およびアプリケーションのクラッシュSupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map);
と同様のバリエーションが、すべてのケースで私が取得されますmapFragmentの場合はnull
この問題を解決するにはどうすればよいですか?
あなたはフラグメントのための 'onCreateView'を使うようになりました。エラーが何であるかを知るためにここにログを投稿できますか? –
もし私が 'onCreateView'を使うと、私はまだこのエラーを受け取ります。あなたは私の質問の更新でエラー報告を見ることができます –
私は解決策を見つけました。ありがとう:) –