2013-11-26 9 views
6

अंदर मैं एक मुद्दा जहां मैं एक android.app.Dialogएंड्रॉयड टुकड़ा संवाद

यहाँ में एक fragment दिखाने की जरूरत है एक्सएमएल कोड

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <FrameLayout 
     android:id="@+id/marchecharts" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </FrameLayout> 

</LinearLayout> 

क्या मैं चाहता हूँ मेरी टुकड़ा द्वारा marchecharts को बदलने के लिए है, किसी को भी यह कर सकते हैं है मदद

धन्यवाद

Dialog dialog = new Dialog(getActivity()); 
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.setContentView(R.layout.marche_charts_parent); 


//this is the part I think I need 
Fragment fragment = new MarcheChartsFragment(); 
FragmentTransaction ft = ((FragmentActivity) dialog.getOwnerActivity()).getFragmentManager().beginTransaction(); 
ft.replace(R.id.marchecharts, fragment); 
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); 
ft.addToBackStack(null); 
ft.commit(); 

dialog.setCanceledOnTouchOutside(true); 
dialog.getWindow().setLayout(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); 
dialog.show(); 

उत्तर

7

Usu सहयोगी आप सीधे DialogFragment का उपयोग करते हैं जिसका नाम स्वयं समझाया गया है।

यहां मेरे कोड का एक उदाहरण है int तर्क के रूप में भेजें।

तो मूल रूप से आप DialogFragment बनाते हैं जो DialogFragment फैलाता है। आपको newInstance और onCreateDialog विधियां लिखनी होंगी। फिर आप कॉलिंग खंड में उस खंड का एक नया उदाहरण बनाते हैं।

public class YourDialogFragment extends DialogFragment { 
    public static YourDialogFragment newInstance(int myIndex) { 
     YourDialogFragment yourDialogFragment = new YourDialogFragment(); 

     //example of passing args 
     Bundle args = new Bundle(); 
     args.putInt("anIntToSend", myIndex); 
     yourDialogFragment.setArguments(args); 

     return yourDialogFragment; 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     //read the int from args 
     int myInteger = getArguments().getInt("anIntToSend"); 

     View view = inflater.inflate(R.layout.your_layout, null); 

     //here read the different parts of your layout i.e : 
     //tv = (TextView) view.findViewById(R.id.yourTextView); 
     //tv.setText("some text") 

     return view; 
    } 
} 

संवाद खंड को बुलाकर ऐसा करके एक और टुकड़े से किया जाता है। ध्यान दें कि मान 0 है जो मैं भेजता हूं।

YourDialogFragment yourDialogFragment = YourDialogFragment.newInstance(0); 
YourDialogFragment.show(getFragmentManager().beginTransaction(), "DialogFragment"); 

आपके मामले में अगर आप कुछ भी पारित करने के लिए, DialogFragment में इसी तर्ज हटाने और YourDialogFragment.newInstance()

संपादित में किसी भी मूल्य में उत्तीर्ण नहीं होते/पालन की जरूरत नहीं है

वास्तव में अपने प्रश्न को समझना सुनिश्चित नहीं है। यदि आपको बस किसी अन्य टुकड़े को प्रतिस्थापित करने की आवश्यकता है तो आप

getFragmentManager().beginTransaction().replace(R.id.your_fragment_container, new YourFragment()).commit(); 
+0

आपकी प्रतिक्रिया के लिए धन्यवाद! मुझे क्रिएटडिअलॉग में कोई त्रुटि मिली: टाइप मिस्चैच: दूसरे दृश्यों पर "रिटर्न व्यू" लाइन –

+0

पर व्यू टू डायलॉग में कनवर्ट नहीं किया जा सकता है, मुझे नहीं लगता कि यह समस्या का उत्तर देता है, क्योंकि मेरे पास पहले से ही एक टुकड़ा है, मुझे बस दिखाने की ज़रूरत है यह एक संवाद में –

+0

जहां तक ​​मैं आपका प्रश्न समझता हूं। आप एक संवाद में अपना खुद का टुकड़ा प्रदर्शित करना चाहते हैं। यदि यह आपका प्रश्न है तो कोड मैं प्रदान करता हूं। – HpTerm

संबंधित मुद्दे