2つのフラグメントとメインアクティビティがあります。フラグメントAのリストのアイテムがクリックされ、IDがメインアクティビティで取得され、2番目のフラグメントが最初のものに置き換えられます。これは、メインアクティビティ内の次のインタフェース方法で発生します。現在使用しているレイアウトアプリケーションを決定する
@Override
public void onCLicked(int id) {
//Launch Fragment B/Pass id to it
}
これは電話画面でうまくいきます。
これで、フラグメントが並んでいるタブレットの2番目のレイアウトを作成しました。私の新しいレイアウトは、私のリソースレイアウト-sw720ランドフォルダにあり、次のようになります。
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<FrameLayout
android:id="@+id/container"
android:layout_width="600dp"
android:layout_height="0dp"
tools:context="com.markf.popularmovies.activities.MainActivity"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
</FrameLayout>
<FrameLayout
android:id="@+id/containerDetail"
android:layout_width="600dp"
android:layout_height="0dp"
tools:context="com.markf.popularmovies.activities.MainActivity"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/container"
app:layout_constraintRight_toRightOf="parent">
</FrameLayout>
</android.support.constraint.ConstraintLayout>
私はタブレットを使用していますが、私は項目をクリックすると、フラグメントAがフラグメントBに置き換えている場合は、このレイアウトが起動しますあたかもそれが電話に残っているかのように。私はこれを適切にコーディングすることができるので、プログラムでどのレイアウトImを決定する方法はありますか? Android Developer:Communicating with Other Fragments
が、運
IDと 'FrameLayout'を想定するとは' containerDetail'は 'findViewById(R.id.containerDetail)は' nullを返した場合、あなたはしている、携帯電話のレイアウトではありません電話レイアウト。 –
意味があります。それは動作します。あなたは答えることができ、私は受け入れます。ありがとう! –