Skip to content

Instantly share code, notes, and snippets.

@johncodeos johncodeos/Fragment1.kt
Last active Aug 13, 2019

Embed
What would you like to do?
class Fragment1: Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.fragment_1, container, false)
return rootView
}
}
class Fragment2: Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.fragment_2, container, false)
return rootView
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<EditText
android:id="@+id/input_edittext"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:textColor="@android:color/white"
android:textStyle="bold"
/>
<Button
android:id="@+id/enter_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter"
android:textStyle="bold"
android:textColor="@android:color/white"
android:padding="10dp"
android:textAllCaps="false"
android:background="@color/colorPrimaryDark"
/>
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:gravity="center">
<TextView
android:id="@+id/output_textview"
android:textColor="@android:color/white"
android:textStyle="bold"
android:textSize="22sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//Replace Main Activity content with the Fragment1 content
val Fragment1 = Fragment1()
supportFragmentManager.beginTransaction().replace(R.id.content_id, Fragment1).commit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.