2016-05-09 11 views
1

私は今すぐ私のために働くonInfoWindowClickメソッドのコードを持っています。マーカーをクリックして断片を開始する必要があります。フラグメントonInfoWindowを呼び出すメソッドを呼び出す

@Override 
public void onInfoWindowClick(Marker marker) { 

    String m = markerMap.get(marker.getId()); 

    if (m.equals("a1")) { 
     Intent i = new Intent(MapsActivity.this, ActividadPrincipal.class); 
     startActivity(i); 
    } 
    else if (m.equals("b1")){ 
     Intent i = new Intent(MapsActivity.this, ActividadPrincipal.class); 
     startActivity(i); 
    } 
} 

答えて

0

@Override 
public void onInfoWindowClick(final Marker marker) { 

    final String m = markerMap.get(marker.getId()); 
    ...... 

    try { 

     new Handler().postDelayed(new Runnable() { 

      @Override 
      public void run() { 
       callFragment(m); 
      } 
     }, 100); 


     return; 
    } catch (Exception e) { 
     Log.e("Exception", "Exception :: " + e.getMessage()); 
    } 
} 

private void callFragment(String id) { 
    YourFragment fragment = new YourFragment(); 
    Bundle b = new Bundle(); 
    b.putString("ID", id); 
    fragment.setArguments(b); 
    FragmentManager fragmentManager = getChildFragmentManager(); 
    fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit(); 
} 
0

あなたは、ダイアログの断片を使用することができます...これを試してみてください。ここで小さな例です。ここで

はあなたのfragment_sample_dialogのレイアウト

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="center" 
    android:padding="10dp" 
    android:orientation="vertical"> 

    <ImageView 
     android:id="@+id/image" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/image" /> 

    <TextView 
     android:id="@+id/title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Lorem ipsum dolor sit amet..." 
     android:textSize="20dp" /> 

    <Button 
     android:id="@+id/dismiss" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Dismiss" /> 
</LinearLayout> 

ここではDialogfragment Javaファイルである:ここでは

public class MyDialogFragment extends DialogFragment { 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     View rootView = inflater.inflate(R.layout.fragment_sample_dialog, container, false); 
     getDialog().setTitle("Simple Dialog"); 
     return rootView; 
    } 
} 

命令は、あなたのフラグメントを起動する方法されています

FragmentManager fm = getFragmentManager(); 
MyDialogFragment dialogFragment = new MyDialogFragment(); 
dialogFragment.show(fm, "Sample Fragment"); 
関連する問題