2016-01-23 81 views
3

是否可以調用MainActivity控件TextViewFragment?我不知道這是否可能。

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> 

現在,我打電話FrameLayoutFragment當有人點擊滑塊菜單項。我想在片段中找到TextView控件。有可能,如果是的話,那麼如何?這就好像在WebFormAsp.net中調用MasterPage控制。

+0

'getActivity()findViewById(R.id.textId)'。您可以在onViewCreated(View v){v.findViewById(...);} – Raghunandan

+0

查找片段中活動的視圖謝謝。它解決了我的問題。現在,當我從Slider調用'OptionsMenu'時,它不會在'TextView'中顯示任何東西。我應該爲此做些什麼改變? –

回答

3

是的,它是可能的。
你可以嘗試這樣的:

TextView textview = (TextView) getActivity().findViewById(R.id.txtpoint); 
textview.setText("Something you write"); 
+0

中使用'getActivity()' –

+0

@Jeeten Parmar wlcm親愛的..... hv a gud day –