2016-03-29 86 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是什么明白的是,一个小部件的静态参考是一个不好的做法,因为这可能导致内存泄漏在某些情况下。

相关问题