私の持ってFragmentActivity
いる 2Fragments
と. にはがあります。の とを作成する必要があります。のイベントのメソッドを呼び出しました。メソッドは次のとおりです。FragmentA
fragmentB
FragmentA
button
onClick
fragmentA
button
TextView
EditText
FragmentB
FragmentB
onCick
FragmentA
button
public void updateFragmentB(String t) {
TextView tv = new TextView(getActivity().getApplicationContext());
tv.setText(t);
}
しかし、それは機能していません。
FragmentB の onCreate メソッドは次のとおりです。
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myFragmentView = inflater.inflate(R.layout.fragment_b, container, false);
b_received = (TextView)myFragmentView.findViewById(R.id.b_received);
b_received.setText("Wait For the text");
tv = new EditText(getActivity().getApplicationContext());
String myTag = getTag();
((AndroidViewPagerActivity)getActivity()).setTabFragmentB(myTag);
return myFragmentView;
}
私の fragment_b レイアウト:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="It's Fragment B" />
<TextView
android:id="@+id/b_received"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="@drawable/ic_launcher"/>
</LinearLayout>