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