是否可以調用MainActivity
控件TextView
到Fragment
?我不知道這是否可能。
有DrawerLayout
它包含TextView
。驗證佈局包含TextView
。從MainActivity調用TextView到Android中的片段
<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
當有人點擊滑塊菜單項。我想在片段中找到TextView
控件。有可能,如果是的話,那麼如何?這就好像在WebForm
的Asp.net
中調用MasterPage
控制。
'getActivity()findViewById(R.id.textId)'。您可以在onViewCreated(View v){v.findViewById(...);} – Raghunandan
查找片段中活動的視圖謝謝。它解決了我的問題。現在,當我從Slider調用'OptionsMenu'時,它不會在'TextView'中顯示任何東西。我應該爲此做些什麼改變? –