私は Android プロジェクトに取り組んでおり、フラグメントを使用してタブレットに適したアプリの UI を作成する方法を考えています。しかし、フラグメント A で何が起こるかに応じてフラグメント B を更新する方法がわかりません。ある種のインターフェイスが必要であることはわかっていますが、それを実装する方法がわかりません。
基本的に、私が持っているのは、フラグメントのレイアウトを設定する MainActivity というアクティビティです。
横向きモードでは、XML ファイルは .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <fragment android:name="com.BoardiesITSolutions.FragmentTest.FragmentA"
        android:id="@+id/list"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="match_parent">
    </fragment>
    <FrameLayout android:id="@+id/viewer"
        android:layout_weight="1"
        android:layout_width="0px"
        android:layout_height="match_parent"
        android:background="?android:attr/detailsElementBackground">
    </FrameLayout>
</LinearLayout>
ポートレートモードでは
現在、MainActivityは、メソッドSetContentView内で使用して、コンテンツ ビューを上記の XML ファイルに設定するだけです。onCreate以下はその外観です。

FragmentAクラスファイルでは、ListFragmentを拡張し、アイテムのListViewを含みます。私ができるようにしたいのは、フラグメントAで選択されたものに基づいてフラグメントB内のテキストビューを更新することです.
以下は、フラグメント A のコードです。
@Override
    public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState)
    {
        return inflator.inflate(R.layout.fragment_a, container, false);
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState)
    {
        super.onActivityCreated(savedInstanceState);
        myListView = getListView();
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("Item1");
        arrayList.add("Item2");
        arrayList.add("Item3");
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(), 
                android.R.layout.simple_list_item_activated_1, arrayList);
        setListAdapter(arrayAdapter);
        View fragmentB = getActivity().findViewById(R.id.viewer);
        mDualPane = fragmentB != null && fragmentB.getVisibility() == View.VISIBLE;
        if (savedInstanceState != null)
        {
            mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);
        }
        if (mDualPane)
        {
            myListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            showDetails(mCurCheckPosition);
        }
    }
    @Override
    public void onListItemClick(ListView l, View view, int position, long id)
    {
        showDetails(position);
    }
    private void showDetails(int index)
    {
        mCurCheckPosition = index;
        if (mDualPane)
        {
            myListView.setItemChecked(index, true);
            FragmentB details = (FragmentB)getFragmentManager().findFragmentById(R.id.viewer);
            if (details == null || details.getShownIndex() != index)
            {
                details = FragmentB.newInstance(index);
                FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.viewer, details);
                fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
                fragmentTransaction.commit();
            }
        }
        else
        {
            Intent intent = new Intent(getActivity(), FragmentBActivity.class);
            intent.putExtra("index", index);
            startActivity(intent);
        }
    }
    @Override
    public void onSaveInstanceState(Bundle outState)
    {
        super.onSaveInstanceState(outState);
        outState.putInt("curChoice", mCurCheckPosition);
    }
FragmentB には次のコードが含まれています。このクラスは Fragment を拡張します。
public View onCreateView(LayoutInflater inflator, ViewGroup container, Bundle savedInstanceState)
    {
        if (container == null)
        {
            return null;
        }
        View view = inflator.inflate(R.layout.fragment_b, container, false);
        return view;
    }
    public static FragmentB newInstance(int index)
    {
        FragmentB fragmentB = new FragmentB();
        Bundle args = new Bundle();
        args.putInt("index", index);
        //rgs.putString("content", content);
        fragmentB.setArguments(args);
        return fragmentB;
    }
    public int getShownIndex()
    {
        return getArguments().getInt("index", 0);
    }
FragmentB の Activity ファイルには、次の内容が含まれています。
@Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {
            finish();
            return;
        }
        if (savedInstanceState == null)
        {
            FragmentB fragmentB = new FragmentB();
            fragmentB.setArguments(getIntent().getExtras());
            getFragmentManager().beginTransaction().add(android.R.id.content, fragmentB).commit();
        }
    }
上のスクリーンショットからわかるように、フラグメントの動作の基礎があり、各アイテムをクリックすると、現在選択されているアイテムが表示されますが、フラグメント b のテキストビューを更新するように指示する方法がわかりませんユーザーがフラグメント a からクリックしたものと、これが縦向きと横向きの両方のモードでどのように処理されるかに基づいています。
ご協力いただきありがとうございます。