android 怎么在activity中改变fragment里面的内容

2025-04-06 03:37:30
推荐回答(1个)
回答1:

1、首先在Activity里动态加载Fragment,
BlankFragment blankFragment = new BlankFragment();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction beginTransaction = fragmentManager.beginTransaction();
beginTransaction.add(R.id.fragmentcontent, blankFragment);
beginTransaction.addToBackStack(null);
beginTransaction.commit();

2、然后在Fragment里的onAttach()方法中获得Activity的Textview控件的引用,