2011-04-08 9 views
10

तो मैं एक DialogFragment कि है कि यह लॉन्च होने से इस techniqueएक DialogFragment

अब के माध्यम से संवाद के रूप में और इस पॉपअप मैं इस संवाद के लिए एक और टुकड़ा में स्लाइड करने के लिए चाहते हैं के भीतर एक उपयोगकर्ता इंटरेक्शन के दिखाया गया है बना लिया है साथ FragmentTransaction का उपयोग करना । मैं FragmentTransaction.add() के माध्यम से ऐसा करने की कोशिश कर रहा हूं जहां मैं इसे इस लेआउट में कंटेनरों में से एक की आईडी देता हूं। इस बिंदु पर मैं:

java.lang.IllegalArgumentException: No view found for id 0x7f09013f for fragment <fragmentClassThatIWasPushingIn> 

एक त्वरित परीक्षण के रूप में, मैं एक कंटेनर आईडी पर यह पुश करने के लिए संवाद में नहीं है, लेकिन मुख्य समर्थन गतिविधि के भीतर करने की कोशिश की और कहा कि ठीक काम किया।

क्या डायलॉगफ्रेगमेंट्स और इसके कंटेनर आईडी के बारे में कुछ है जो FragmentTransactions के लिए अनुमति नहीं देता है?

स्टॉपगैप के रूप में मैंने अपने लेनदेन को वर्तमान डायलॉग फ्रैगमेंट को छिपाने के लिए कहा है और यह नया टुकड़ा दिखाया है, लेकिन एनीमेशन/डिस्प्ले थोड़ा झटकेदार है इसलिए मैं वास्तव में इस समस्या को हल करना चाहता हूं।

धन्यवाद

उत्तर

16

जब एक DialogFragment एक Dialog के रूप में दिखाया गया है यह वास्तव में एक कंटेनर ध्यान में रखते हुए एक असली Fragment नहीं है। यह एक कंटेनर-कम Fragment है जो मूल रूप से Dialog का एक आवरण है।

तो नहीं, आप FragmentDialog के अंदर Fragment नहीं दिखा सकते हैं। यदि आप वास्तव में ऐसा करना चाहते हैं तो मुझे लगता है कि को Dialog के रूप में स्टाइल किया गया है, जिसे आप Fragments भी जोड़ सकते हैं।

+0

यह सही है। हालांकि DialogFragment को setShowsDialog (झूठी) के साथ एक टुकड़ा के रूप में कार्य करने के लिए मजबूर किया जा सकता है; मेरा जवाब जांचें। – macieksk

1

वास्तव में एक कंटेनर है जैसा कि आप ऑनक्रेट व्यू विधि में देख सकते हैं। आप अपना दृश्य बनाने के लिए कंटेनर का उपयोग करते हैं।

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle icicle) { 
    Log.d(TAG, "onCreateView"); 
    View v = inflater 
      .inflate(R.layout.move_folder_dialog, container, false); 

ऐसा लगता है कि FragmentManager कंटेनर प्राप्त करने में सक्षम नहीं है।

क्या यह एक बग हो सकता है?

3

alexanderblom सही है कि एक संवाद के रूप में DialogFragment कार्य करता है, लेकिन यह setShowsDialog(false);

के साथ एक टुकड़ा अंत में मेरे लिए काम किया निम्नलिखित के रूप में कार्य करने के लिए किया जा सकता है:

फ़ाइल: res/लेआउट/wifidirect_dialog_wifidirect :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:id="@+id/dialog_wifidirect_layout"> 

    <LinearLayout 
     android:id="@+id/frag_container" 
     android:layout_width="match_parent" 
     android:layout_height="250dp" 
     android:orientation="vertical" > 

      <!-- This is replaced during runtime --> 
      <RelativeLayout 
       android:id="@+id/frag_list" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="top" > 
      </RelativeLayout> 
    </LinearLayout> 

    <!-- The Cancel Button --> 
    <View 
    android:layout_width="fill_parent" 
    android:layout_height="1dp" 
    android:layout_marginBottom="0dp" 
    android:background="?android:attr/dividerVertical" /> 
    <Button 
     android:id="@+id/dialog_wifidirect_cancel" 
     style="?android:attr/buttonBarButtonStyle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/cancel"/>   
</LinearLayout> 

फ़ाइल src /.../ WifiDirectDialog.java:

public class WiFiDirectDialog extends DialogFragment { 
     public static final String TAG = "WifiDirectDialog"; 
     public static final String DEVICE_LIST_FRAGMENT_TAG = "WIFIDIRECT_DEVICE_LIST_FRAGMENT"; 


     public static WiFiDirectDialog newInstance(){     
      WiFiDirectDialog wDialog = new WiFiDirectDialog(); 
      //We want this Dialog to be a Fragment in fact, 
      //otherwise there are problems with showing another fragment, the DeviceListFragment 
      wDialog.setShowsDialog(false); 
      //wDialog.setStyle(SherlockDialogFragment.STYLE_NORMAL,android.R.style.Theme_Holo_Light_Dialog); 
      //We don't want to recreate the instance every time user rotates the phone 
      wDialog.setRetainInstance(true); 
      //Don't close the dialog when touched outside 
      wDialog.setCancelable(false); 
      return wDialog; 
     } 


     @Override 
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
      Log.v(TAG,"onCreateView"); 

      View view = inflater.inflate(R.layout.wifidirect_dialog_wifidirect,container, false); 

      //Log.v(TAG,"FragmentTransaction started");    
      ListFragment listFragment = new YourListFragment(); 

      FragmentTransaction transaction = getChildFragmentManager().beginTransaction(); 
      transaction.addToBackStack(DEVICE_LIST_FRAGMENT_TAG) 
       .replace(R.id.frag_list,deviceListFragment,DEVICE_LIST_FRAGMENT_TAG) 
       .commit(); 
      //Log.v(TAG,"FragmentTransaction finished"); 

      return view; 
     }; 

     @Override 
     public void onActivityCreated(Bundle savedInstanceState){ 
      Log.v(TAG,"onActivityCreated"); 
      super.onActivityCreated(savedInstanceState); 

      Dialog dialog = getDialog(); 
      dialog.setTitle(R.string.wifidirect_dialog_title); 

      // Set button listeners etc.../// 
      Button cancelButton = (Button) view.findViewById(R.id.dialog_wifidirect_cancel); 
      cancelButton.setOnClickListener(new View.OnClickListener() { 
       public void onClick(View v) {     
        dismiss(); 
       } 
      }); 
     } 
संबंधित मुद्दे