Utworzono plik xml o nazwie editor.xml, który zawiera FrameLayout. W mojej głównej działalności próbuję dodać mój niestandardowy fragment do mojego FrameLayout.Próbuję dodać fragment do mojego kontenera fragmentu FrameLayout
Błąd zgłaszany, gdy próbuje dodać mój fragment brzmi:
Metoda add (int, Fragment) w typie FragmentTransaction nie dotyczy argumentów (int, editorFrag)
Jednak moja editorFrag Rozciąga Fragment, więc jestem zdezorientowany, dlaczego tak się dzieje. Poniżej znajduje się mój kod dla plików, o których wspomniałem. Każda pomoc jest doceniana.
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);
}
}
}
odpowiedział:
Luksprog odpowiedział ten problem dla mnie poniżej informując mnie do c sprawdź mój import. Eclipse wybrał opcję importowania wersji Fragment zestawu SDK zamiast wymaganej wersji pomocy technicznej. Dziękuję za pomoc.
Sprawdź importu. Sprawdź, czy nie zaimportowano '' SDK' '' Fragment' zamiast pakietu kompatybilności 'Fragment'. – Luksprog
Masz całkowitą rację, pozwoliłem, aby zaimportowano zaćmienie i rzeczywiście wybrałem wersję SDK, w której w mojej działalności wybrała wersję wsparcia. Bardzo dziękuję – Pedrom
@ Mind umysłu akceptując odpowiedź na to pytanie? Dzięki. http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work –