Hey guys I have fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.recordings, container, false);
}
Here is my layout
<RelativeLayout 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:id="@+id/recordinglayout">
How would I get this fragment object without adding it to my activity? Or add something, for instance like a button to fragment's layout from activity class?
答案 0 :(得分:0)
An activity cannot reference a fragment that has not been instantiated somehow. You can instantiate a fragment via the fragment tag in xml, or create one programmatically in Java.
I suggest you take a close look at the documentation on creating (and referencing) fragments :)