###前提・実現したいこと
ActivityのToolbar上にあるボタン(Item)を押した時に
そのActivityにあるFragment上のデータ(EditTextの内容など)を取得するにはどうすればいいのでしょうか?
##Activityのレイアウト
XML
1<layout> 2 <LinearLayout 3 xmlns:android="http://schemas.android.com/apk/res/android" 4 xmlns:app="http://schemas.android.com/apk/res-auto" 5 android:id="@+id/parentLayout" 6 android:layout_width="match_parent" 7 android:layout_height="match_parent" 8 android:background="@color/colorBackground" 9 android:orientation="vertical"> 10 11 <android.support.v7.widget.Toolbar 12 android:id="@+id/tool_bar" 13 android:layout_width="match_parent" 14 android:layout_height="wrap_content" 15 android:background="?attr/colorPrimary" 16 android:minHeight="?attr/actionBarSize" 17 android:theme="@style/ThemeOverlay.AppCompat.ActionBar"> 18 19 </android.support.v7.widget.Toolbar> 20 21 <fragment 22 android:id="@+id/setting_fragment" 23 android:layout_width="match_parent" 24 android:layout_height="match_parent" 25 android:name="freeprojects.oldbigbuddha.kyoto.alarmapplication.Fragmennts.SettingFragment" /> 26 27 </LinearLayout> 28</layout>
ToolbarのLayout
XML
1<?xml version="1.0" encoding="utf-8"?> 2<menu xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto"> 4 <item 5 android:id="@+id/create_menu" 6 android:icon="@mipmap/ic_create" 7 app:showAsAction="always" 8 android:title="create_menu" /> 9 10</menu>
考えている動作
create_menuを押した時に、setting_fragment上のデータを取得して保存する
使っているもの
DataBindingを使っています
学習コストの関係で、MVVMにはできていないので
Butterknifeの代わりに使ってる感じです
データの保存にはRealmを使っています
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。