2016-03-29 97 views
-1

我想通過單擊fragment2中的按鈕來更改fragment1中文本視圖中的文本,我設法通過將文本視圖聲明爲static,以便我可以通過更改文本Fragment1.textv.setText("hi");,這是好的,什麼是最好的方式來做到這一點。片段訪問控件來自同一活動中的另一個片段

static textv ; 
@Override 
public View onCreateView( LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    final View v = inflater.inflate(R.layout.fragment_frag_beam_rec, container, false); 

    textv= (TextView)v.findViewById(R.id.textview); 

      return v; 
} 

回答

1

爲user3806331說你需要使用的接口,跟隨鏈接,你會發現你need.but是什麼明白的是,一個小部件的靜態參考是一個不好的做法,因爲這可能導致內存泄漏在某些情況下。

相關問題