2017-05-02 1 views
-1

WishlistFragment와 GoShoppingFragment의 두 조각과 "쇼핑 계속"단추가 있습니다. 버튼을 클릭하면 WishlistFragment가 GoShoppingFragment로 바뀝니다.하나의 조각을 다른 단추로 추가하고 바꿉니다.

이것은 onClick의 구현입니다. 그때 WishlistFragment이 GoShoppingFragment relaced됩니다 "쇼핑 계속"버튼을 클릭하지만 this 같은 출력을 얻을 때 여기

public void onClickShopNow() { 
    FragmentManager fragmentManager = getFragmentManager(); 
    Fragment fragment = new GoShoppingFragment(); 
    fragmentManager 
      .beginTransaction() 
      .replace(R.id.container, fragment) 
      .addToBackStack(null) 
      .commit(); 
    if(fragmentManager.getBackStackEntryCount() > 0) { 
     fragmentManager.popBackStackImmediate(); 
    } 
} 

문제이다. WishlistFragment는 백그라운드에 남아 있습니다. 이 문제를 어떻게 해결합니까?

GoShopping 레이아웃 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".ui.store.goshopping.GoShoppingFragment"> 
<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/swipe_refresh_go_shopping" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:visibility="gone"> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_go_shopping" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</android.support.v4.widget.SwipeRefreshLayout> 
<ProgressBar 
    android:id="@+id/progress_bar" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:visibility="visible" /> 
<LinearLayout 
    android:id="@+id/moreLoading" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_alignParentBottom="true" 
    android:background="@color/transparent" 
    android:gravity="center" 
    android:orientation="horizontal" 
    android:visibility="gone"> 
    <ProgressBar 
     android:id="@+id/moreLoadingIndicator" 
     style="?android:attr/progressBarStyleSmall" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="10dp" 
     android:layout_marginStart="10dp" 
     android:text="@string/label_loading_more" /> 
</LinearLayout></RelativeLayout> 

위시리스트 레이아웃 : 당신의 조각과 setClickable (참)의

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/container" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="io.launchbyte.appio.ui.store.mywishlist.MyWishlistFragment"> 

<LinearLayout 
    android:id="@+id/layout_continue_shopping" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:orientation="vertical" 
    android:visibility="gone"> 

    <TextView 
     android:id="@+id/txt_wishlist_empty" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:padding="8dp" 
     android:text="@string/wishlist_empty" /> 

    <TextView 
     android:id="@+id/txt_wishlist_add_items" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:padding="8dp" 
     android:text="@string/wishlist_add_items" /> 

    <Button 
     android:id="@+id/button_continue_shopping" 
     android:layout_width="150dp" 
     android:layout_height="48dp" 
     android:layout_gravity="center" 
     android:layout_marginTop="24dp" 
     android:background="@drawable/primary_color_button_selector" 
     android:text="@string/continue_shopping" /> 
</LinearLayout> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recycler_my_wishlist" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fadeScrollbars="true" 
     android:visibility="gone" /> 

    <ProgressBar 
     android:id="@+id/progress_bar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:visibility="visible" /> 
</RelativeLayout></FrameLayout> 
+0

통해 이동 희망 : -> HTTP : //stackoverflow.com/questions/12958555/android-replace-fragment-still-displays-some-of-replaced-fragment 및 http://stackoverflow.com/questions/6925941/get-fragments-container-view-id –

+0

활동 클래스에서 사용되는 자원 ID를 사용해야합니다. – Krish

답변

1

설정 배경 당신의 조각 XML의 각각의 내부.

+0

이것은 내가 뭘 찾고있어, 전경 조각 (GoShopping) 만 볼 수 있도록 배경 조각 (WishlistFragment) 제거 싶어요. – Shrikant

+0

이 줄을 제거하십시오 - addToBackStack (null) –

+0

이미 그것을, 아직도 동일한 산출 – Shrikant

0

이 제거 또한

if(fragmentManager.getBackStackEntryCount() > 0) { 
    fragmentManager.popBackStackImmediate(); 
} 

당신의 GoShopping layout:에 루트 태그 추가 기능에 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clickable="true" 
android:background="?android:attr/windowBackground" 
tools:context=".ui.store.goshopping.GoShoppingFragment"> 
0
public void onClickShopNow() { 

    FragmentManager fragmentManager = getFragmentManager(); 

    Fragment fragment = new GoShoppingFragment(); 
    Fragment WishlistFragment = 
    fragmentManager.getFragmentByTag("TagName"); 

    fragmentManager 
      .beginTransaction() 
      .remove(WishlistFragment) 
      .commit(); 

    fragmentManager 
      .beginTransaction() 
      .add(R.id.container, fragment,"TagHere") 
      .commit(); 

} 

을 나는이 당신을 도울 ..

관련 문제