隐藏Fragment类中包含的布局中的textview

时间:2019-05-03 05:55:45

标签: java android fragment

我正在寻找解决方案,以从framgmetnt类内的所包含布局隐藏textview。我尝试去给片段xml中的包含布局提供ID,并执行以下代码,但仍在显示。

我的片段xml是

 <?xml version="1.0" encoding="utf-8"?>

    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:paddingBottom="4dp"
    android:paddingLeft="2dp"
    android:paddingRight="2dp"
    android:paddingTop="4dp">



    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none" />


    </FrameLayout>
    <include
        android:id="@+id/include_tag"
        layout="@layout/row_item"/>
    </android.support.v4.widget.SwipeRefreshLayout>

并且我的row_item xml包括了

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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="wrap_content"
    >


        <TextView
            android:id="@+id/flower_Name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="This need to Visible"/>

       

                <TextView
                    android:id="@+id/flower_details"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="This need to Hide "/>

            </LinearLayout>


        </LinearLayout>



    </RelativeLayout>

最后我的Fragment类具有以下代码

        public View onCreateView(final LayoutInflater inflater, @Nullable      final ViewGroup container, @Nullable Bundle savedInstanceState) {
    view = inflater.inflate(R.layout.activity_main, container, false);

    View test1View = view.findViewById(R.id.include_tag);
    mhideText = (TextView)test1View.findViewById(R.id.flower_details);
    mhideText.setVisibility(View.INVISIBLE);
    return  view;

如果您需要更多信息。.请让我知道,并先感谢您的帮助。

0 个答案:

没有答案