【发布时间】:2016-01-23 05:45:46
【问题描述】:
是否可以调用MainActivity控制TextView到Fragment?我不知道这是否可能。
有DrawerLayout,它包含TextView。验证布局包含TextView。
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerLayout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="@color/lightish" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lightish" />
<include layout="@layout/validation" />
</RelativeLayout>
<ListView
android:id="@+id/lvSlider"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/dark_gray"
android:choiceMode="singleChoice"
android:divider="@color/dark_gray"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_item_selector" />
</android.support.v4.widget.DrawerLayout>
现在,当有人单击滑块菜单项时,我在 FrameLayout 中调用 Fragment。我想在 Fragment 中找到 TextView 控件。有可能吗,如果是,那怎么办?就像在WebForm 中调用MasterPage 控件在Asp.net 中一样。
【问题讨论】:
-
getActivity().findViewById(R.id.textId)。您可以使用getActivity()在片段中找到活动视图 -
in onViewCreated(View v){ v.findViewById(...);}
标签: android android-fragments android-framelayout