2017-12-24 2 views
0

Ich entwickle eine Umfrage-Anwendung das Problem, das ich konfrontiert ist, dass ein Layout enthält eine Frage TextView Ja/Nein RadioGroup und ein Bemerkungen EditText Feld. Also ich ein Layout erstellen, das diese Dinge enthält und in meinem fragment für 5-10 Mal je nach Anzahl der Fragen. Die Frage wird dynamisch über den Code gestellt. Es ist eine Tab-Aktivität mit 4-5 Tabs/Fragmente, jetzt nachdem ich die gewünschte Option ausgewählt und Anmerkungen eingegeben habe, wechselte ich zur nächsten Registerkarte, aber wenn ich zur selben Registerkarte zurückkehrte, repliziert der Wert in der letzten Ansicht zu allen auf dieser Registerkarte verfügbaren Ansichten. Die Registerkarte wird geändert, sobald der Benutzer auf die nächste Schaltfläche klickt. Der Wechsel zwischen den Registerkarten ist deaktiviert, und beim nächsten Klick werden alle Daten im Modell gespeichert (für die Einreichung auf der letzten Registerkarte) und die nächste Registerkarte ist über den Code viewPager.setCurrentItem(1); aktiv. Obwohl Modelldaten nicht temperiert ist aber Ansichtsdaten wirdAufrufe Wert verloren auf Registerkartenwechsel

meine benutzerdefinierten Layout verloren:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:paddingBottom="10dp" 
android:paddingTop="10dp"> 

<TextView 
    android:id="@+id/tvTitle" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingBottom="10dp" 
    android:paddingTop="10dp" 
    android:textColor="@color/black" 
    android:textStyle="bold" /> 

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

    <RadioGroup 
     android:id="@+id/rgOptions" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:orientation="horizontal"> 

     <RadioButton 
      android:id="@+id/rgYes" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="false" 
      android:text="@string/yes" /> 

     <Space 
      android:layout_width="20dp" 
      android:layout_height="wrap_content" /> 

     <RadioButton 
      android:id="@+id/rgNo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:checked="false" 
      android:text="@string/no" /> 
    </RadioGroup> 

</RelativeLayout> 

<EditText 
    android:id="@+id/etRemarks" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:ems="10" 
    android:hint="@string/remarks" 
    android:inputType="textMultiLine" /> 

Fragment xml: kann

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:paddingBottom="@dimen/activity_vertical_margin" 
      android:paddingLeft="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_horizontal_margin" 
      android:paddingTop="@dimen/activity_vertical_margin"> 

<Button 
     android:id="@+id/bt_odetails" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Next"/> 

      <include 
       android:id="@+id/view1" 
       layout="@layout/observerlayoutcustom1" /> 

      <include 
       android:id="@+id/view2" 
       layout="@layout/observerlayoutcustom1" /> 

      <include 
       android:id="@+id/view3" 
       layout="@layout/observerlayoutcustom1" /> 

      <include 
       android:id="@+id/view4" 
       layout="@layout/observerlayoutcustom1" /> 

      <include 
       android:id="@+id/view5" 
       layout="@layout/observerlayoutcustom1" /> 

      <include 
       android:id="@+id/view6" 
       layout="@layout/observerlayoutcustom1" /> 

      <include 
       android:id="@+id/view7" 
       layout="@layout/observerlayoutcustom1" /> 

      <include 
       android:id="@+id/view8" 
       layout="@layout/observerlayoutcustom1" /> 

</LinearLayout> 

Antwort

1

setOffScreenPageLimit Methode von viewpager lösen dieses Problem. set viewpager offScreenpageLimit auf 4

Verwandte Themen