android - Get fragment layout from its id -
i'm trying change fragments inside activity in android application.
i want code method which, based on button's id changes fragment inside view, problem in myfragment class
public static class myfragment extends fragment { public registerfragment(int id){ this.id = id; } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { xmlresourceparser layout = getresources().getlayout(r.id.this.id); view rootview = inflater.inflate(layout, container, false); return rootview; } } my problem getresources().getlayout(r.id.some-random-id); givin error
resource id type not valid i'm using method because want make dynamic choose of fragment layout, based, indeed, on id.
i use android:id retrieve di layout
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id ="@+id/register_fragment" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/background_blue" > am using bad approach?
cheers
r.id give of views id, layouts (activities, fragments..) located in r.layout tried access isn't located in r.id, hence not giving id.
Comments
Post a Comment