Le fragment de remplacement Android affiche toujours une partie du fragment remplacé
J'ai un onglet qui contient un linéaire de la mise en page avec un searchview et une listview. Lorsque l'utilisateur clique sur l'un des résultats de la recherche, je veux remplacer cette mise en page avec une autre mise en page contenant les détails de la sélection.
Ce qui se passe lorsque je remplace la recherche fragment seulement la listview partie de la mise en page sera remplacé; le searchview est toujours visible et actif sur l'écran.
Voici ma recherche de mise en page:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<SearchView
android:id="@+id/public_calendar_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:iconifiedByDefault="false"
</SearchView>
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1.0"
android:choiceMode="singleChoice" />
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center"/>
</LinearLayout>
Voici le détail de mise en page:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/detail_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical" >
<Space
android:layout_width="0dip"
android:layout_height="20dip"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal" >
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".1" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".8"
android:text="@string/label_Name" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".1" />
</LinearLayout>
.........
</LinearLayout>
Et mon code pour remplacer la recherche de fragment:
FragmentTransaction transaction = getFragmentManager().beginTransaction();
//Replace whatever is in the fragment_container view with this fragment,
//and add the transaction to the back stack.
DetailFragment fragment = DetailFragment.newInstance(cal);
transaction.replace(R.id.search_layout, fragment);
transaction.addToBackStack(null);
transaction.commit();
Détail fragment de création:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.detail_layout, container, false);
return v;
}
static DetailFragment newInstance(String cal) {
DetailFragment d = new DetailFragment();
return d;
}
Ce que je fais mal? Comment puis-je obtenir l'intégralité de la recherche de mise en page pour être remplacé.
Merci!
source d'informationauteur sitecrawl
Vous devez vous connecter pour publier un commentaire.
J'ai compris mon problème. Marco n'était pas exactement, mais il m'a dirigé dans la bonne direction.
Le problème était le numéro du conteneur, j'étais de passage pour le remplacement de la méthode est l'ID du fragment, j'étais remplaçant, pas l'ID de l'fragment de récipient. Cela semble expliquer pourquoi certains de l'original fragment de contrôles ont été restant après la remplacer - l'ensemble de ce fragment n'a pas été remplacé.
Je l'ai changé pour obtenir le fragment de conteneur affichage de l'ID, et ça a fonctionné! Voici le code:
J'ai trouvé la réponse pour obtenir le conteneur affichage de l'ID d'un fragment ici, Obtenir fragment du conteneur affichage de l'id.
J'ai été en utilisant l'ID correct, alors qu'il n'était pas près de disparaître. S'avère que vous devez définir la
Background color
à votre couleur nécessaire à nouveau Fragment de mise en page, comme ceci.Pour résoudre le problème, définissez le android:propriété d'arrière-plan “?android:windowBackground” dans le fragment fichiers de mise en page.
Dans Fragment_2