2017-04-18 3 views
0

2つのフラグメントを含むタブ付きアクティビティであるMainactivityを持っています... 両方のフラグメントにはフォームが含まれます.... メインアクティビティには1つのボタンがあります.... 今、メインアクティビティコンテナのこのボタンをクリックすると、両方のフラグメントからフォームデータを取得できますか?以下は2つのフラグメントと1つのコンテナアクティビティのボタンを持つタブ付きアクティビティ次にフラグメントの両方からデータを取得する方法

つのタブ 各タブが含まれて私の主な活動は、私は2つのフラグメントのクラスを作成している登録ボタンがあり 充填するフォームが含まれている断片...

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/main_content" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:context="com.example.dellpc.eventsbox.EventDetails"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="@dimen/appbar_padding_top" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleMarginBottom="@dimen/height" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed" 
     > 



     <ImageView 
      android:id="@+id/profile_id" 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:background="@drawable/akgec1" 
      android:fitsSystemWindows="true" 
      android:scaleType="centerCrop" 
      app:layout_collapseMode="parallax" 
      /> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/height_double" 
      android:layout_gravity="top" 
      app:layout_collapseMode="pin" 


      /> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 

      android:layout_height="@dimen/height" 
      android:layout_gravity="bottom" 
      app:tabTextColor="#607D8B" 
      app:tabGravity="fill" 
      app:tabMode="fixed" 
      /> 

    </android.support.design.widget.CollapsingToolbarLayout> 




</android.support.design.widget.AppBarLayout> 



<android.support.v4.view.ViewPager 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

<Button 
    android:id="@+id/registerEventBTN" 
    android:layout_height="55dp" 
    android:layout_gravity="bottom" 
    android:layout_width="match_parent" 
    android:text="REGISTER ON THIS" 
    android:background="#caE45a" 
    > 

</Button> 

を持っています2つのフォームのために、私はメインのコンテナにフラグメントを接続するためにSectionPageAdapterを使用しています....

問題: - フラグメントにはボタンが含まれていません... 唯一のボタンは、私がフラグメント の両方で満たされたすべてのデータを取得するには、このボタンを使用したいが、私はこれを行う方法を取得していないです...コンテナクラスに ..です

答えて

0

メーカーの種類を助けてくださいあなたが必要とする変数を含んでいます。ビューにリスナーを設定し、両方のフラグメントでsetterを使用して、ユーザーからの値/入力をオブジェクト/モデルに渡します。あなたは、ボタンをホストしている主なアクティビティにあなたのモデルを渡すインターフェイスを実装する必要があります。モデルを分割可能にします。

関連する問題