#java #android
#Ява #Android
Вопрос:
В моем приложении у меня есть несколько фрагментов, на большинстве из которых есть TextInputLayout (для создания выпадающего меню «Материал»), и, нажав так много раз в выпадающем меню, откроется другой фрагмент! Я попытался установить идентификатор для TextInputLayout для каждого фрагмента, но, изменив один идентификатор, все остальные TextInputLayout получат этот идентификатор!!
В этом приложении я работаю с контейнером фрагментов и NestedScrollView с помощью MaterialCardviews.
activity_main.xml Код:
lt;androidx.coordinatorlayout.widget.CoordinatorLayout 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"gt; lt;com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content"gt; lt;androidx.appcompat.widget.Toolbar android:id="@ id/toolbar_main" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_scrollFlags="scroll|enterAlways" app:titleTextColor="@color/white" /gt; lt;/com.google.android.material.appbar.AppBarLayoutgt; lt;androidx.fragment.app.FragmentContainerView android:id="@ id/frame_main_fragmentContainer" android:name="com.mohajer.kitset2.MainFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" /gt; lt;/androidx.coordinatorlayout.widget.CoordinatorLayoutgt;
фрагмент_майна кода:
lt;androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#F2F2F2"gt; lt;LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"gt; lt;include layout="@layout/layout1" /gt; lt;include layout="@layout/layout2" /gt; ... lt;include layout="@layout/layout10" /gt; lt;/LinearLayoutgt; lt;/androidx.core.widget.NestedScrollViewgt;
in Main_fragment class I’m using .add transaction with transaction.addToBackStack(null) for each fragment.
also this event Makes the main_fragment toolbar to be appear on other fragment that don’t have a toolbar , because that i have set this code for them to hide the Toolbar:
@Override public void onResume() { super.onResume(); ((AppCompatActivity)getActivity()).getSupportActionBar().hide(); } @Override public void onStop() { super.onStop(); ((AppCompatActivity)getActivity()).getSupportActionBar().show(); }