I have a tabbed interface in Android and use a FrameLayout as my main layout in my app. I'm getting an Android Lint warning that says:
This <FrameLayout> can be replaced with a <merge\> tag
The only place I use this FrameLayout (named fragmentContainer) is in the onTabSelected listener. Here's a simplified version.
@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
// When the given tab is selected, show the tab contents in the
// container
Fragment fragment;
String tag;
switch (tab.getPosition()) {
case 0:
fragment = new myFragment1();
tag = "myFragment1";
break;
case 1:
fragment = new new myFragment2();
tag = "myFragment2";
break;
default:
Log.d(TAG, "invalid tab selected: " + tab.getPosition());
break;
}
fragmentTransaction.replace(R.id.fragmentContainer, fragment, tag);
}
This works well, but I'd love to improve performance if possible, and get rid of any Lint warnings I can. If I replace the FrameLayout with a merge tag, I can't call that fragmentTransaction() because the id doesn't exist anywhere.
Here's the FrameLayout for completeness:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" />