我想通過單擊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;
}