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.
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.