Kürzlich habe ich ein Projekt von Eclipse nach Android Studio migriert. Alles ist eingerichtet und funktioniert gut, außer für mein ein Fragment, das ein SupportMapFragment verwendet. Die unten findFragmentById (das funktioniert, wenn in Eclipse Aufbau) wird nun der Rückkehr null :(findFragmentById für SupportMapFragment gibt null in Android Studio zurück
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
SupportMapFragment m = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.safety_map));
Snippet xml ...
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/safety_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="40dp"
map:cameraTargetLat="@string/livesafe_latitude"
map:cameraTargetLng="@string/livesafe_longitude"
map:uiZoomControls="false"
class="com.google.android.gms.maps.SupportMapFragment"/>
Hier sind meine Abhängigkeiten in meinem build.gradle:
dependencies {
//google analytics
compile 'com.google.apis:google-api-services-analytics:v3-rev103-1.19.0'
//support library for api 10
compile 'com.android.support:support-v4:21.0.0'
//google play services
compile 'com.google.android.gms:play-services:6.1.11'
compile project(':facebook')
compile files('libs/android-support-multidex.jar')
compile files('libs/aws-android-sdk-1.6.0-debug.jar')
compile files('libs/FlurryAnalytics_3.3.2.jar')
}
ich habe keinen Code in der xML-Datei oder das Fragment Klasse geändert, die in Eclipse zuvor gearbeitet.
was lsActivity ist? Könnten Sie stattdessen getActivity() ausprobieren? – Y2i
versucht mit getActivity() statt aber kein Glück .... lsActivity wird nur verwendet, um alle meine Aktivitäten erweitert ein Common und das ist nur so, ich muss nicht überall tippen. lsActivity = (MeineAktivität) getActivity(); meine Frage bearbeitet, um diese Verwirrung für andere zu vermeiden –
tun Sie das Sir, nur einen Rückruf-Test .. kopieren Sie diesen Code und setzen Sie es in onresume() von Ihrem Fragment lifeclycle .. wenn es nicht Null zurückgibt, nun, es wird ein Callback Lil Problem, wenn es passiert, rufen Sie es direkt von Ihrem oncreatview-Methode und erhalten Sie die ID aus dem überhöhten Layout..directly .. hoffe, es hilft Ihnen .. – Elltz