J'ai une application très simple avec une seule activité et FrameLayout
dedans. J'ai deux mises en page A et B et je les charge comme des fragments un à la fois remplaçant ainsi le fragment courant. Le problème est que lorsque j'appuie sur le bouton de retour, l'application se bloque. Le changement de fragment est déclenché par un bouton dans le premier fragmentApp se bloque en revenant à fragment précédent dans la pile
MainActivity.java
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Check that the activity is using the layout version with
// the fragment_container FrameLayout
if (findViewById(R.id.fragment_container) != null) {
// However, if we're being restored from a previous state,
// then we don't need to do anything and should return or else
// we could end up with overlapping fragments.
if (savedInstanceState != null) {
return;
}
else {
// Create a new Fragment to be placed in the activity layout
SelectLogInFragment firstFragment = new SelectLogInFragment();
// In case this activity was started with special instructions from an
// Intent, pass the Intent's extras to the fragment as arguments
firstFragment.setArguments(getIntent().getExtras());
// Add the fragment to the 'fragment_container' FrameLayout
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, firstFragment).commit();
}
}
}
public void login_email(View view)
{
// Create fragment and give it an argument specifying the article it should show
Log_In_form newFragment = new Log_In_form();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack so the user can navigate back
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
}
SelectLogInFragment.java
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class SelectLogInFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.select_log_in, container, false);
}
}
LoginForm est très similaire à SelectLogInFragment
select_log_in.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.badass.david.mynewapplication.Top_Log"
android:id="@+id/top_log"
android:layout_weight="2"
android:layout_width="match_parent"
android:layout_height="0dp" />
<fragment android:name="com.badass.david.mynewapplication.Bottom_Log"
android:id="@+id/bottom_log"
android:layout_weight="2"
android:layout_width="match_parent"
android:layout_height="0dp" />
</LinearLayout>
Top_Log.java
public class Top_Log extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.top_log, container, false);
}
}
Bottom_Log est très similaire
top_log.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="center"
android:background="@color/white" >
<TextView
android:id="@+id/logo_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Put Logo here" />
</LinearLayout>
erreurs
06-20 12: 00: 06,773 20327-20327/com.badass.david.mynewapplication E/AndroidRuntime: EXCEPTION FATALE: main processus: com.badass.david.mynewapplication, PID: 20327 android.view.InflateException: ligne fichier XML binaire # 6: Erreur gonflage des fragments de classe à android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:770) à android.view.LayoutInflater.rInflate (LayoutInflater.java:813) à android.view.LayoutInflater.inflate (LayoutInflater.java:511) à android.view.LayoutInflater.inflate (LayoutInflater.java:415) à com.badass.david.mynewapplication.SelectLogInFragment.onCreateView (SelectLogInFragment.java:16) à android.support.v4.app.Fragment.performCreateView (Fragment.java:1974) à android.support.v4.app.FragmentManagerImpl.moveToState (FragmentManager.java:1067) à android.support.v4 .app.FragmentManagerImpl.moveToState (FragmentManager.java:1252) à android.support.v4.app.BackStackRecord.popFromBackStack (BackStackRecord.java:979) à android.support.v4.app.FragmentManagerImpl.popBackStackState (FragmentManager .java: 1670) au android.support.v4.app.FragmentManagerImpl.popBackStackImmediate (FragmentManager.java:5 86) à android.support.v4.app.FragmentActivity.onBackPressed (FragmentActivity.java:188) à android.app.Activity.onKeyUp (Activity.java:2576) à android.view.KeyEvent.dispatch (KeyEvent .java: 3171) at android.app.Activity.dispatchKeyEvent (Activity.java:2831) à com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchKeyEvent (PhoneWindow.java:2438) à android.view.ViewRootImpl $ ViewPostImeInputStage.processKeyEvent (ViewRootImpl.java:4582) à android.view.ViewRootImpl $ ViewPostImeInputStage. OnProcess (ViewRootImpl.java:4537) à android.view.ViewRootImpl $ InputStage.deliver (ViewRootImpl.java:4068) à android.view.ViewRootImpl $ InputStage.onDeliverToNext (ViewRootImpl.java:4121) à android .view.ViewRootImpl $ InputStage.forward (ViewRootImpl.java:4087) at android.view.ViewRootImpl $ AsyncInputStage.forward (ViewRootImpl.java:4201) à android.view.ViewRootImpl $ InputStage.apply (ViewRootImpl.java:4095) à android.view.ViewRootImpl $ AsyncInputStage.apply (ViewRootImpl. java: 4258) à android.view.ViewRootImpl $ InputStage.deliver (ViewRootImpl.java:4068) à android.view.ViewRootImpl $ InputStage.onDeliverToNext (ViewRootImpl.java:4121) à android.view.ViewRootImpl $ InputStage.forward (ViewRootImpl.java:4087) à android.view.ViewRootImpl $ InputStage.apply (ViewRootImpl.java:4095) à android.view.ViewRootImpl $ InputStage.deliver (ViewRootImpl.java:4068) à android.view.ViewRootImpl $ InputStage.onDeliverToNext (ViewRootImpl.java:4121) à android.view.ViewRootImpl $ InputStage.forward (ViewRootImpl.java:4087) à android.view.ViewRootImpl $ AsyncInputStage.forward (ViewRootImpl.java:4234) à android.view.ViewRootImpl $ ImeInputStage.onFinishedInputEvent (ViewRootImpl.java:4421) à android. view.inputmethod.InputMethodManager $ PendingEvent.run (InputMethodManager.java:2480) à android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback (InputMethodManager.java:2074) à android.view.inputmethod.InputMethodManager.finishedInputEvent (InputMethodManager.java:2065) à android.view.inputmethod.InputMethodManager $ ImeInputEventSender .onInputEventFinished (InputMethodManager.java:2457) à android.view.InputEventSender.dispatchInputEventFinished (InputEventSender.java:141) à android.os.MessageQueue.nativePollOnce (Méthode natif) à android.os.MessageQueue.next (MessageQueue .java: 143) à android.os.Looper.loop (Looper.java:130) à android.app.ActivityThread.main (ActivityThread.java:5951) à java.lang.reflect.Method.invoke (méthode native) à java. lang.reflect.Method.invoke (Method.java:372) au com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:1388) à com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1183) causés par: java.lang.IllegalArgumentException: fichier XML binaire ligne
6: id en double 0x7f0c0089, null tag, ou l'identifiant parent 0xffffffff avec un autre fragment de com.badass.david.mynewapplication.Top_Log
at
android.support.v4.app.FragmentManagerImpl.onCreateView (FragmentManager.java:2293) à android.support.v4.view.LayoutInflaterCompatHC $ usine
Pour moi, il semble qu'il essaie de créer un fragment qui existe déjà, donc il y a un conflit d'ID .. Est-ce le problème? Comment puis-je le résoudre?
' com.badass.david 'votre espace de noms est appelé badass c'est ce qui rend Android studio en colère et il jette un er ror. – Vucko