2

I am trying to get a two pane display for the android tablet I was trying to test the application on a emulator (Nexus 10). I created an activity_man.xml for the same (in folder layout-sw600dp). It contains a FrameLayout exclusive to it with the android:id="@+id/movie_detail_container" as mentioned below.

  activity_main.xml
<LinearLayout 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"
    android:baselineAligned="false"
    android:divider="?android:attr/dividerHorizontal"
    android:orientation="horizontal"
    tools:context="akshit.android.com.popularmovies.MainActivity">

    <!--
    This layout is a two-pane layout for the Items master/detail flow.
    -->

    <fragment
        android:id="@+id/fragment_movie_main"
        android:name="akshit.android.com.popularmovies.MainActivityFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
        tools:layout="@android:layout/list_content" />

    <FrameLayout
        android:id="@+id/movie_detail_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="4" />

</LinearLayout>

Based on this, I had a check that if the view contains the id, I should have mTwoPane = true as well as launch DetailFragment(to support the movie_details_container). However mTwoPane is staying as false.

public class MainActivity extends AppCompatActivity {
    private static final String DETAILFRAGMENT_TAG = "DFTAG";

    boolean mTwoPane = false;
    public static String TAG = MainActivity.class.getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        if (findViewById(R.id.movie_detail_container) != null) {
            mTwoPane = true;
            Log.i(TAG, "mTwoPane value=" + mTwoPane);
            if (savedInstanceState == null) {
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.movie_detail_container, new DetailsActivityFragment(), DETAILFRAGMENT_TAG)
                        .commit();
            }
        } else {
            mTwoPane = false;
            Log.i(TAG, "mTwoPane value=" + mTwoPane);

        }

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            Intent intent = new Intent(getApplicationContext(), SettingsActivity.class);
            startActivity(intent);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Please help me figuring out as where am I going wrong.

Aleksandar G
  • 1,163
  • 2
  • 20
  • 25
  • Your emulator does not appear to be loading the desired resource. Either that, or your resources are not in the locations that you are expecting. You might wish to log the value of `smallestScreenWidthDp` on a `Configuration` object (e.g., `getResources().getConfiguration()` on your `Activity`) to see what it reports. A real Nexus 10 should use `res/layout-sw600dp/` resources, assuming that there is not a better match for that resource. – CommonsWare May 14 '16 at 14:21
  • you print mTwoPane variable before you change it's value to true Log.i(TAG, "mTwoPane value=" + mTwoPane); mTwoPane = true; – visionix visionix May 15 '16 at 06:53
  • I figured out that the device (emulator of Nexus 10 ) I was using had sw of 400dp. I thought that Nexus 10 being having sw of 800 dp would be used that way. – Akshit Gupta May 15 '16 at 08:02

2 Answers2

0

Create new virtual device without frame. AVD Manager->create virtual device->tablet->nexus 10 ->next -> select sdk ->next -> uncheck "enable device frame"

If it helped please mark as answered.

Sebastian M
  • 629
  • 7
  • 17
0

Have you checked that the id of your movie detail layout in the relevant layout.xml file is also set as movie_detail_container ? It should match with the id given in activity_main.xml file's FrameLayout id.

Riddhi
  • 61
  • 1
  • 7