2016-04-20 48 views
-2

我想知道,如何從android中的對話框單擊操作中調用片段。該對話框在另一個活動中。如何從android中的對話框中調用片段?

下面

是對話框部分代碼

public static void Bookingconfirm(final Context _context, String title,String strMessage) 
{ 
    final Dialog dialog1 = new Dialog(_context); 

    Log.e("Point","1"); 
    dialog1.setContentView(R.layout.booking_success); 
    dialog1.setCanceledOnTouchOutside(true); 
    dialog1.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); 
    dialog1.findViewById(R.id.d_location); 
    LinearLayout btnok = (LinearLayout) dialog1.findViewById(R.id.booking_ok); 


    btnok.setOnClickListener(new OnClickListener() 
    { 

     @SuppressLint("NewApi") @Override 
     public void onClick(View arg0) 
     { 
      Log.e("Point","2"); 

      //i wanted the click to fragment here 
      // parent class of fragment Home.java and fragment is booking.java 


     } 
    }); 


    dialog1.show(); 

} 

回答

0
Fragment fragment= booking.newInstance(); 
Home mainActivity = (Home) context; 
     FragmentManager manager = mainActivity.getSupportFragmentManager(); 
     FragmentTransaction transaction = manager.beginTransaction(); 
     transaction.replace(R.id.container, fragment, "Frag"); 
     transaction.commit(); 

嘗試從您的對話框中點擊監聽器上面的代碼......希望這有助於

0

試試下面的代碼:

FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); 
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); 
fragmentTransaction.replace(R.id.content_frame, new booking()); 
fragmentTransaction.commit(); 
相關問題