Search code examples
javaandroidandroid-activityandroid-tabs

Is it possible to have 2 activities in 1 layout in android?


I am beginner with developing in Android Studio... I created 2 tabs with 2 different activities. Both of them have the search function. So is it possible to have 2 activities in 1 layout in Android Studio?


Solution

  • Create two activity as activity1.java and activity2.java
    Then in activity_main create 2 fragment and pass their activity name at "android:name"
    <fragment android:name="com.example.activity1" android:id="@+id/fragment_place" android:layout_width="match_parent" android:layout_height="match_parent" />
    <fragment android:name="com.example.activity2" android:id="@+id/fragment_place" android:layout_width="match_parent" android:layout_height="match_parent" />