Прежде всего - я новичок в Android.Я создал несколько пользовательских классов представления, как показано ниже.
- CustomViewBaseClass
- CustomViewOne расширяет CustomViewBaseClass
- CustomViewTwo расширяет CustomViewBaseClass
- CustomViewThree расширяет CustomViewBaseClass
В моем файле макета я добавил CustomViewOne, как показано ниже
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.test.custom.CustomViewOne
android:id="@+id/cvone"
android:layout_width="match_parent"
android:layout_height="100dp"
android:visibility="visible" />
</LinearLayout>
Это работает нормально, как и ожидалось.
Но я хочу динамически заменить это CustomViewOne на CustomViewTwo/ CustomViewThree для некоторых событий (нажатие кнопки и т. Д.)
Как сделать это во время выполнения?