2017-12-24 3 views
0

調査アプリケーションを開発しています。私が直面している問題は、レイアウトに質問TextViewはい/いいえRadioGroupと備考EditTextが含まれていることです。 だから私はこれらのものを含むレイアウトを作成し、質問の数に応じて私のfragmentに5-10時間を含める。質問はコードによって動的に設定されます。 これは、4-5タブ/断片を含むタブ付きアクティビティです。必要なオプションを選択してコメントを入力すると次のタブに移動しましたが、同じタブに戻ったときに、最後のビューの値はそのタブで使用できるすべてのビューにレプリケートされます。ユーザーが次のボタンをクリックするとタブが変更され、次のクリックで次のクリックですべてのデータがモデルに保存され(最後のタブで送信)、次のタブはコードviewPager.setCurrentItem(1);でアクティブになります。モデルデータが焼きではなく、ビューデータが タブの変更でビューの値が失われる

を失っているが、私のカスタムレイアウト:

<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" /> 

フラグメントのxml:viewpagerの

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

答えて

1

setOffScreenPageLimit方法は、解決することがありこの問題。 viewpagerのoffScreenpagelimitを4に設定

関連する問題