Изменение значения TextView из MainActivity

Подскажите, пожалуйста, как передать данные из MainActivity на TextView, который находиться на одном из фрагментов при использовании

    <androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity">


<FrameLayout
    android:id="@+id/fl_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:visibility="visible"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="@android:color/darker_gray"
    app:layout_constraintBottom_toBottomOf="@+id/fl_content"
    app:menu="@menu/navigation" />
   </androidx.constraintlayout.widget.ConstraintLayout>

Ответы (1 шт):

Автор решения: Andrew

Для таких целей можно использовать bundle. Посылаем текст:

Bundle bundle = new Bundle();
bundle.putString("edttext", "From Activity");
// set Fragmentclass Arguments
Fragmentclass fragobj = new Fragmentclass();
fragobj.setArguments(bundle);

получаем стринг и сетим его в дальше в виджет:

String strtext = getArguments().getString("edttext");

можно кроме текста отправить и числа и всякое разное. Вот есть документация по Bundle

→ Ссылка