2017-05-03 1 views
0

Ich entwickle Anwendung und bekomme einen Fehler null für den Zugriff Fragment aus Dialogfeld Layout-Datei im Dialogfeld. Eigentlich möchte ich Karte in einem Dialogfeld beim Klicken auf Listenansicht innerhalb eines Pager-Fragments anzeigen.Dialogfeld mit Karte innerhalb Pager-Fragment in Android

Dialog-Layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/map_view" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<fragment 
    android:id="@+id/mapevent" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    class="com.google.android.gms.maps.SupportMapFragment" 
    /> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Close" 
    android:id="@+id/close" 
    android:background="@null" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" /> 

Fragment-Datei und Dialog, in dem ich Dialog bin Befestigung. seine Arbeits, während ich versuche ich Karte Objekt hinzufügen Markierung zu erhalten dann nicht bin immer Gegenstand von Support-Karte Fragment

public class Event extends Fragment { 
private ListView listView; 
. 
. 
. 
@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    View view = inflater.inflate(R.layout.fragment_item_three, container, false); 
    if(map_dialog==null) 
    map_dialog= new Dialog(getActivity()); 

    listView = (ListView) view.findViewById(R.id.event_list); 
    dialog.show(); 
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { 
      dialog.show(); 

      map_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      map_dialog.setContentView(R.layout.dialog_layout); 
      map_dialog.show(); 

      MapsInitializer.initialize(getActivity()); 
      FragmentManager myFragmentManager = getActivity().getSupportFragmentManager(); 
      mMapView = (SupportMapFragment)myFragmentManager.findFragmentById(R.id.map); 
      mMapView.onCreate(map_dialog.onSaveInstanceState()); 
      mMapView.onResume();// needed to get the map to display immediately 
      mMapView.getMapAsync(new OnMapReadyCallback() { 
       @Override 
       public void onMapReady(GoogleMap googleMap) { 

        latLng=new LatLng(Double.parseDouble(eventList.get(position).getLat()),Double.parseDouble(eventList.get(position).getLng())); 
        googleMap.addMarker(new MarkerOptions().position(latLng)); 
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(15)); 
        dialog.dismiss(); 
       } 
      }); 
     } 
    }); 
+0

das Crash-Protokoll schreiben .... – rafsanahmad007

Antwort

0

Try this:

FragmentManager myFragmentManager = getActivity().getSupportFragmentManager(); 
mMapView = (SupportMapFragment) myFragmentManager.findFragmentById(R.id.mapevent); 

Für Dialog können Sie MapView stattdessen verwenden von SupportMapFragment.

<com.google.android.gms.maps.MapView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/map" /> 

diese Fragment in Ihrem Do:

MapView mMapView; 


listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
    @Override 
    public void onItemClick(AdapterView<?> parent, View view, final int position, long id) { 

     dialog.show(); 

     map_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     map_dialog.setContentView(R.layout.dialog_layout); 
     map_dialog.show(); 

     mMapView = (MapView) map_dialog.findViewById(R.id.map); 
     mMapView.onCreate(map_dialog.savedInstanceState); 
     mMapView.onResume();// needed to get the map to display immediately 

     try { 
      MapsInitializer.initialize(this.getActivity()); 
     } catch (GooglePlayServicesNotAvailableException e) { 
      e.printStackTrace(); 
     } 

     mMapView.getMapAsync(new OnMapReadyCallback() { 
      @Override 
      public void onMapReady(GoogleMap googleMap) { 

       latLng = new LatLng(Double.parseDouble(eventList.get(position).getLat()),Double.parseDouble(eventList.get(position).getLng())); 
       googleMap.addMarker(new MarkerOptions().position(latLng)); 
       googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); 
       googleMap.animateCamera(CameraUpdateFactory.zoomTo(15)); 
       dialog.dismiss(); 
      } 
     }); 
    } 
}); 
+1

nicht funktioniert Ich habe es bereits überprüfen Sie geändert Id gerade tatsächlich vergessen zu Ich schreibe, aber ich bin mit gleicher ID beidseitig. Aber danke für Versuch und Bemühungen –

+0

versuchen Sie meinen aktualisierten Code mit mapview – FAT

+0

immer noch Null beim Abrufen von Google Map-ID –