谢谢楼上我这个代码是网上的,它从Activity到fragment直接就用 public void onArticleSelected(int position) { // The user selected the headline of an article from the HeadlinesFragment // Capture the article fragment from the activity layout KRZT_Cont articleFrag = (KRZT_Cont) getSupportFragmentManager().findFragmentById(R.id.krzt_cont_frag);
if (articleFrag != null) { // If article frag is available, we're in two-pane layout... // Call a method in the ArticleFragment to update its content articleFrag.updateArticleView(position); } } 没有调用transaction.commit我想保留这种方式,可以在这个基础上传递数据吗?
f.setMyValue(params); 你这样传进去负值。
然后再提交给Fragment Transaction Management
2.fragment与activity交互通过接口回调机制
3.activity与fragment交互例子:
//传递数据
Bundle myBundle=new Bundle();
myBundle.putString("data", "myFirstData");
Fragment myFragment=new Fragment();
myFragment.setArguments(myBundle);
FragmentManager fManager=getFragmentManager();
FragmentTransaction fTransaction=fManager.beginTransaction();
fTransaction.add(R.id.container,myFragment,"myTag");
fTransaction.commit();
//获得数据
String data=getFragmentManager().findFragmentByTag("myTag").getArguments().getString("data");
public void onArticleSelected(int position) {
// The user selected the headline of an article from the HeadlinesFragment
// Capture the article fragment from the activity layout KRZT_Cont articleFrag = (KRZT_Cont)
getSupportFragmentManager().findFragmentById(R.id.krzt_cont_frag);
if (articleFrag != null) {
// If article frag is available, we're in two-pane layout... // Call a method in the ArticleFragment to update its content
articleFrag.updateArticleView(position);
}
}
没有调用transaction.commit我想保留这种方式,可以在这个基础上传递数据吗?