我在
Android中有一个标签式界面,并在我的应用程序中使用FrameLayout作为我的主要布局.我收到一条Android Lint警告说:
This can be replaced with a tag
我使用此FrameLayout(名为fragmentContainer)的唯一位置是onTabSelected侦听器.这是一个简化版本.
@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);
}
这很好用,但我希望尽可能提高性能,并尽可能摆脱任何Lint警告.如果我用合并标记替换FrameLayout,我不能调用fragmentTransaction(),因为id在任何地方都不存在.
这是FrameLayout的完整性:
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" />