मैंने एक XML फ़ाइल बनाई है जिसे editor.xml कहा जाता है जिसमें फ़्रेमलेआउट होता है। मेरी मुख्य गतिविधि में मैं अपने फ्रेमलेआउट में अपना कस्टम टुकड़ा जोड़ने की कोशिश कर रहा हूं।मेरे टुकड़े के कंटेनर में एक टुकड़ा जोड़ने की कोशिश कर रहा है FrameLayout
त्रुटि मैं प्राप्त जब मेरे टुकड़ा जोड़ने की कोशिश कर रहा है:
विधि जोड़ें (पूर्णांक, टुकड़ा) प्रकार FragmentTransaction में तर्क के लिए लागू नहीं है (पूर्णांक, editorFrag)
हालांकि मेरी editorFrag फ्रैगमेंट बढ़ाता है इसलिए मैं उलझन में हूं कि यह क्यों हो रहा है। मेरे द्वारा उल्लिखित फ़ाइलों के लिए नीचे मेरा कोड है। किसी भी मदद की सराहना की है।
Editor.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
editorFrag.java
public class editorFrag extends Fragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
// Inflate the layout for this fragment
return inflater.inflate(R.layout.newlevel, container, false);
}
}
MainActivity.java
public class editorActivity extends FragmentActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.editor);
// Check that the activity is using the layout version with the fragment_container FrameLayout
if(findViewById(R.id.fragment_container) != null)
{
// if we are being restored from a previous state, then we dont need to do anything and should
// return or else we could end up with overlapping fragments.
if(savedInstanceState != null)
return;
// Create an instance of editorFrag
editorFrag firstFrag = new editorFrag();
// add fragment to the fragment container layout
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, firstFrag);
}
}
}
उत्तर दिया:
Luksprog मुझे बता द्वारा नीचे मेरे लिए इस समस्या को जवाब सी के लिए मेरे आयात बिल्ली। ग्रहण ने मुझे आवश्यक समर्थन संस्करण की बजाय टुकड़े के एसडीके संस्करण को आयात करना चुना। सहायता के लिए धनयवाद।
तरह प्रतिबद्ध() अपने आयात की जाँच करें। देखें कि आपने संगतता पैकेज 'Fragment' के बजाय' Fragment' के 'SDK' संस्करण को आयात नहीं किया है या नहीं। – Luksprog
आप बिल्कुल सही हैं, मैंने अपने लिए आयात ग्रहण करने दिया और वास्तव में एसडीके संस्करण का चयन किया जहां मेरी गतिविधि में यह समर्थन संस्करण चुना गया। बहुत धन्यवाद – Pedrom
@ प्राइमडम दिमाग इस सवाल के जवाब को स्वीकार कर रहा है? धन्यवाद। http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work –