2017-10-29 12 views
0

두 번째 단편에서 백 프레스 할 때 첫 번째 단편 (이 단편은 뷰 페이지에 추가됨)에서 이미지 (예 : @ + id/shower) 이 조각은 첫번째 조각 둘째 아이 (상대 레이아웃 즉 @ + ID/view_frame) 나는 두 번째 단편 (registerfragment)를 호출하고 때두 번째 단편에서 뒤로 버튼을 눌렀을 때 첫번째 단편에서 이미지를 변경하는 방법

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:cardview="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:id="@+id/frame_indicators" 
    android:layout_height="wrap_content" 
    cardview:cardUseCompatPadding="true" 

    > 
<LinearLayout 
    android:orientation="vertical" 
    android:gravity="center" 
    android:paddingTop="@dimen/dp10" 
    android:paddingBottom="@dimen/dp10" 
    android:layout_gravity="center_horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <ImageView 
     android:id="@+id/shower" 
     android:layout_width="wrap_content" 
     android:gravity="center" 
     android:scaleType="centerCrop" 
     android:layout_gravity="center_horizontal" 
     android:src="@drawable/first_plan_indicator" 
     android:layout_height="wrap_content"> 


    </ImageView> 
    <LinearLayout 

     android:layout_marginTop="@dimen/dp5" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="3" 
     style="@style/Widget.AppCompat.ButtonBar" 
     android:gravity="center" 
     android:layout_gravity="center_horizontal" 
     android:orientation="horizontal"> 
     <TextView 

      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:textColor="@color/navi_selector" 
      android:id="@+id/choose_plan_text" 
      android:text="Choose Plans"/> 
     <TextView 
      android:gravity="center" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:id="@+id/enter_details_text" 

      android:text="Enter Details"/> 
     <TextView 
      android:gravity="center" 
      android:id="@+id/pay_text" 

      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:textColor="@color/textcolor" 
      android:text="Payment"/> 


    </LinearLayout> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 
<RelativeLayout 
    android:id="@+id/view_frame" 

    android:visibility="visible" 
    android:layout_below="@+id/frame_indicators" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

<LinearLayout 
    android:id="@+id/tabs_type" 
    android:gravity="center" 
    android:layout_centerHorizontal="true" 
    android:layout_width="match_parent" 
    android:weightSum="2" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <LinearLayout 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:layout_width="match_parent" 
      android:gravity="center" 
      android:layout_gravity="center_horizontal" 
      android:padding="@dimen/dp10" 
      android:id="@+id/for_family" 
      android:textColor="@color/black" 
      android:textStyle="bold" 
      android:layout_height="wrap_content" 
      android:text="For Your Family">  </TextView> 

     <View 
      android:id="@+id/family_divider" 
      android:layout_width="match_parent" 
      android:layout_height="3dp" 
      android:layout_marginLeft="5dp" 
      android:layout_marginStart="5dp" 
      android:layout_marginRight="@dimen/dp5" 
      android:layout_marginEnd="@dimen/dp5" 
      android:background="@color/navi_selector"/> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_weight="1" 
     android:layout_width="0dp" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:layout_width="match_parent" 
      android:gravity="center" 
      android:layout_gravity="center_horizontal" 
      android:padding="@dimen/dp10" 
      android:textColor="@color/textcolor" 
      android:id="@+id/for_you" 
      android:layout_height="wrap_content" 
      android:textStyle="bold" 
      android:text="For You">  </TextView> 

     <View 
      android:id="@+id/your_divider" 

      android:visibility="gone" 
      android:layout_marginLeft="5dp" 
      android:layout_marginStart="5dp" 
      android:layout_marginRight="@dimen/dp5" 
      android:layout_marginEnd="@dimen/dp5" 
      android:layout_width="match_parent" 
      android:layout_height="3dp" 
      android:background="@color/navi_selector"/> 
    </LinearLayout> 



</LinearLayout> 
    <android.support.v7.widget.RecyclerView 
     android:layout_marginTop="@dimen/dp5" 
     android:layout_below="@+id/tabs_type" 
     android:id="@+id/packageslist_recyclerview" 
     android:layout_width="match_parent" 
     android:visibility="visible" 
     android:layout_height="wrap_content"> 

    </android.support.v7.widget.RecyclerView> 
</RelativeLayout> 

및 FIRST FRAGMET을 내 코드, 내가 수 있어요로 대체 indicatorChangesNew() 메서드를 호출하여 이미지를 변경합니다.

  if (packagesList.getPackageID()==6) 
     { 
      planListFragmentNew.indicatorChangesNew(1); 
     } 
     else 
    { 
     planListFragmentNew.indicatorChangesNew(2); 
    } 
    FragmentManager fragmanger=mContext.getFragmentManager(); 
    FragmentTransaction fragtrans; 
    fragtrans = fragmanger.beginTransaction(); 
    Bundle b=new Bundle(); 
    b.putDouble("planCost",packagesList.getPackageCost()); 
    b.putString("planName",packagesList.getPackageName()); 
    b.putString("paymode",packagesList.getPackageModeOfPay()); 
    b.putInt("planId",packagesList.getPackageID()); 
    b.putString("role",packagesList.getRolePatient()); 
    RegisterFragment registerFragment=new RegisterFragment(); 
    registerFragment.setArguments(b); 
    fragtrans.replace(R.id.view_frame, registerFragment); 
    fragtrans.addToBackStack(Constants.FRAG_TAG_REGISTER); 
    fragtrans.commit(); 

그리고 내 indicatorChangesNew() 메소드

public void indicatorChangesNew(int checkValue) 
    {if (checkValue==1) 
    {  mChoosePlanText.setTextColor(getResources() 
    .getColor(R.color.textcolor)); 
      mEnterPlanText.setTextColor(getResources() 
     .getColor(R.color.navi_selector)); 
     mPayText.setTextColor(getResources() 
    .getColor(R.color.textcolor)); 
     mShower.setImageDrawable(getResources() 
    .getDrawable(R.drawable.second_plan_indicator)); 
     } 
    else if(checkValue==2) 
    { 
     mChoosePlanText.setTextColor(getResources(). 
     getColor(R.color.textcolor)); 
     mEnterPlanText.setTextColor(getResources() 
     .getColor(R.color.textcolor)); 
     mPayText.setTextColor(getResources() 

     .getColor(R.color.navi_selector)); 
     mShower.setImageDrawable(getResources() 
    .getDrawable(R.drawable.third_plan_indicator)); 
    } 
    else{ 
      mChoosePlanText.setTextColor(getResources() 
     .getColor(R.color.navi_selector)); 
    mEnterPlanText.setTextColor(getResources() 
    .getColor(R.color.textcolor)); 
    mPayText.setTextColor(getResources() 
    .getColor(R.color.textcolor)); 
    mShower.setImageDrawable(getResources() 
.getDrawable(R.drawable.first_plan_indicator));} 
} 
+0

RegisterFragment에서 뒤로 버튼을 누르면 indicatorChangesNew()를 호출하려고합니다. PlanListFragment 안에 있습니다. –

답변

0

사용 공유 환경 설정이나 싱글 톤 클래스 또는 단지 정적 변수입니다.

+0

RegisterFragment에서 뒤로 버튼을 눌렀을 때 indicatorChangesNew()를 호출하려고합니다. 가능한 경우 하나의 샘플을 제공하십시오. 고마워 –