[英]Tabbed Activity with two fragments and a single button in container activity then how to get data from both the fragments
我有一个Mainactivity,它是一个选项卡式活动,其中包含两个片段...两个片段都包含表格.... main活动中只有一个按钮....现在我如何通过单击从两个片段中获取表格数据在主要活动容器中的此按钮上?
下面是我的主要活动,其中包含两个选项卡,每个选项卡都有片段,其中包含要填写的表单。有一个注册按钮...
<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>
我已经为这两种形式创建了两个片段类,并且我正在使用SectionPageAdapter将片段连接到主容器。
问题:-片段不包含任何按钮...唯一的按钮在容器类中...我想使用此按钮来将所有数据填充到两个片段中,但是我没有办法做到这一点。请帮忙
使模型包含所需的变量。 在您的视图上设置侦听器,并使用两个片段上的设置器将值/输入从用户传递到您的对象/模型。 您必须实现接口,该接口会将您的模型从片段传递到主要活动(即托管按钮)。 使模型可分割。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.