2017-10-29 3 views
0

Ich möchte ein Bild (dh @ + id/duschen) im ersten Fragment ändern (dieses Fragment wurde zum viewpager hinzugefügt), wenn ich vom zweiten Fragment backpress dieses Fragment wird durch erstes Fragment zweites Kind (Relative Layout dh @ + id/view_frame)Wie man Bild im ersten Fragment ändert, wenn ich Taste vom zweiten Fragment zurückdrückte

<?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> 

und Ihr Code in FIRST FRAGMET, wenn ich rufe zweites Fragment (registerfragment) ersetzt, ich bin in der Lage Bild durch Aufruf der Methode indicatorChangesNew() ändern.

  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(); 

Und mein indicatorChangesNew() -Methode ist

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

Ich möchte indicatorChangesNew() aufrufen, wenn es innerhalb von PlanListFragment gedrückt wird, wenn Sie auf die Schaltfläche RegisterFragment klicken. –

Antwort

0

Verwendung gemeinsamen Vorlieben oder eine Singleton-Klasse oder nur eine statische Variable.

+0

Ich möchte indicatorChangesNew() aufrufen, wenn ich die Taste von RegisterFragment zurückgedrückt habe, geben Sie bitte eine klare Antwort, wenn es möglich ist, eine Probe zu geben. Danke –

Verwandte Themen