android 数据传递——实例化对象调用方法

来源:互联网 发布:怎么加入农村淘宝网 编辑:程序博客网 时间:2024/06/08 10:02

1、

2、(1)在LeftMenuFragment中添加

      public void SetData(String str){

System.out.println("侧栏接收到的数据是"+str);

}

(2)在Main2Activity中根据标查找Fragment

      //根据fragment标签返回Fragment
public LeftMenuFragment getLeftMenuFragment(){
FragmentManager fm = getSupportFragmentManager();
LeftMenuFragment leftMemuFragment = (LeftMenuFragment)                      fm.findFragmentByTag(FRAGMENT_LEFT_MENU);
   return leftMemuFragment;
}

(3)在NewsPager中获取Main2Activity实体,然后获取leftMemuFragment,调用setData()

1 0
原创粉丝点击