Android Lint says I can replace a layout with a <merge> tag, but I need the id of the layout in a fragment transaction -
i have tabbed interface in android , utilize framelayout main layout in app. i'm getting android lint warning says:
this <framelayout> can replaced <merge\> tag
the place utilize framelayout (named fragmentcontainer) in ontabselected listener. here's simplified version.
@override public void ontabselected(actionbar.tab tab, fragmenttransaction fragmenttransaction) { // when given tab selected, show tab contents in // 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, i'd love improve performance if possible, , rid of lint warnings can. if replace framelayout merge tag, can't phone call fragmenttransaction() because id doesn't exist anywhere.
here's framelayout 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" />
if thing in activity's layout file, rid of layout file , setcontentview()
call, , utilize android.r.id.content
target of fragmenttransaction
. android.r.id.content
points framelayout
setcontentview()
inflates into.
also, please note action bar tabs deprecated in "l" developer preview , should remain deprecated in next production release of android. may wish consider using tab solution (e.g., viewpager
, tabbed indicator) or navigation solution (e.g., navigation drawer).
android android-fragments fragmenttransaction android-lint
No comments:
Post a Comment