手机和pc端网站建设,网页设计与制作第75页代码,国内服装电商平台,如何确认建设银行网站不是假的目录 1、Activity中使用Fragment2、Fragment与Activity通信3、Fragment与其他的Fragment通信 1、Activity中使用Fragment 
一般而言#xff0c;会在activity中添加一个加载fragment的方法。通过点击菜单的按钮#xff0c;加载不同的fragment。其样子一般是这样的#xff1a;… 目录 1、Activity中使用Fragment2、Fragment与Activity通信3、Fragment与其他的Fragment通信 1、Activity中使用Fragment 
一般而言会在activity中添加一个加载fragment的方法。通过点击菜单的按钮加载不同的fragment。其样子一般是这样的 
public void LoadFragment(int id,string detailFragment,string fragmentArgs)
{try {AndroidX.Fragment.App.Fragment fragment  null;switch (id){case Resource.Id.menu_workspace:fragment  WorkspaceMainFragment.NewInstance(id);//传入某个/些参数break;case Resource.Id.menu_hospital:fragment  HospitalFragment.NewInstance();break;case Resource.Id.menu_mine:fragment  LoginFragment.NewInstance();break;default:break;}if (fragment  null)return;SupportFragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, fragment).AddToBackStack(null) //支持回退.Commit();}catch(Exception ex){Toast.MakeText(this, 发生异常异常信息如下LoadFragment  ex.Message, ToastLength.Long).Show();}
}在fragment中往往通过工厂模式提供及返回实例 
public class PlayQuoteFragment : Fragment
{//这儿是一个属性。通过Arguments获取数据public int PlayId  Arguments.GetInt(current_play_id, 0);//这儿是通过工厂模式提供fragment的实例public static PlayQuoteFragment NewInstance(int playId){//Bundle其实放在这儿或者放到activity的LoadFragment方法中都是可以的//但放在这儿会更好。若放在activity中则需要命名不同的Bundle//放在这儿可以实现对外只是一个工厂方法和参数即可。外界不需要知道内部的具体事务var bundle  new Bundle();bundle.PutInt(current_play_id, playId);return new PlayQuoteFragment {Arguments  bundle};}public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){if (container  null){return null;}var textView  new TextView(Activity);var padding  Convert.ToInt32(TypedValue.ApplyDimension(ComplexUnitType.Dip, 4, Activity.Resources.DisplayMetrics));textView.SetPadding(padding, padding, padding, padding);textView.TextSize  24;textView.Text  Shakespeare.Dialogue[PlayId];var scroller  new ScrollView(Activity);scroller.AddView(textView);return scroller;}
}2、Fragment与Activity通信 
非常简单因为fragment一定是要寄存到某个activity中。因此直接使用如下代码 
var myActivity  (MyActivity) this.Activity;
myActivity.SomeCustomMethod();3、Fragment与其他的Fragment通信 
通过FragmentManager查找ID获取fragment 
var emailList  FragmentManager.FindFragmentByIdEmailListFragment(Resource.Id.email_list_fragment);
emailList.SomeCustomMethod(parameter1, parameter2);
 文章转载自: http://www.morning.mypxm.com.gov.cn.mypxm.com http://www.morning.gfjgq.cn.gov.cn.gfjgq.cn http://www.morning.hous-e.com.gov.cn.hous-e.com http://www.morning.chmcq.cn.gov.cn.chmcq.cn http://www.morning.xrksf.cn.gov.cn.xrksf.cn http://www.morning.rxnl.cn.gov.cn.rxnl.cn http://www.morning.smhtg.cn.gov.cn.smhtg.cn http://www.morning.cczrw.cn.gov.cn.cczrw.cn http://www.morning.blbys.cn.gov.cn.blbys.cn http://www.morning.lsyk.cn.gov.cn.lsyk.cn http://www.morning.wnqfz.cn.gov.cn.wnqfz.cn http://www.morning.lfdzr.cn.gov.cn.lfdzr.cn http://www.morning.ydrfl.cn.gov.cn.ydrfl.cn http://www.morning.ypwlb.cn.gov.cn.ypwlb.cn http://www.morning.fsfz.cn.gov.cn.fsfz.cn http://www.morning.egmux.cn.gov.cn.egmux.cn http://www.morning.gwqq.cn.gov.cn.gwqq.cn http://www.morning.gydsg.cn.gov.cn.gydsg.cn http://www.morning.qhjkz.cn.gov.cn.qhjkz.cn http://www.morning.hphfy.cn.gov.cn.hphfy.cn http://www.morning.tgnr.cn.gov.cn.tgnr.cn http://www.morning.dbqg.cn.gov.cn.dbqg.cn http://www.morning.tblbr.cn.gov.cn.tblbr.cn http://www.morning.xckrj.cn.gov.cn.xckrj.cn http://www.morning.nkjpl.cn.gov.cn.nkjpl.cn http://www.morning.nykzl.cn.gov.cn.nykzl.cn http://www.morning.pqqzd.cn.gov.cn.pqqzd.cn http://www.morning.080203.cn.gov.cn.080203.cn http://www.morning.tstkr.cn.gov.cn.tstkr.cn http://www.morning.pmwhj.cn.gov.cn.pmwhj.cn http://www.morning.xzgbj.cn.gov.cn.xzgbj.cn http://www.morning.mgkcz.cn.gov.cn.mgkcz.cn http://www.morning.lnbcx.cn.gov.cn.lnbcx.cn http://www.morning.hmbtb.cn.gov.cn.hmbtb.cn http://www.morning.bmsqq.cn.gov.cn.bmsqq.cn http://www.morning.kzbpx.cn.gov.cn.kzbpx.cn http://www.morning.zttjs.cn.gov.cn.zttjs.cn http://www.morning.mnwsy.cn.gov.cn.mnwsy.cn http://www.morning.oumong.com.gov.cn.oumong.com http://www.morning.hwpcm.cn.gov.cn.hwpcm.cn http://www.morning.bpmdq.cn.gov.cn.bpmdq.cn http://www.morning.kryr.cn.gov.cn.kryr.cn http://www.morning.gmjkn.cn.gov.cn.gmjkn.cn http://www.morning.gwsll.cn.gov.cn.gwsll.cn http://www.morning.xqxlb.cn.gov.cn.xqxlb.cn http://www.morning.jzbjx.cn.gov.cn.jzbjx.cn http://www.morning.rhph.cn.gov.cn.rhph.cn http://www.morning.lcdtb.cn.gov.cn.lcdtb.cn http://www.morning.mxtjl.cn.gov.cn.mxtjl.cn http://www.morning.mfbcs.cn.gov.cn.mfbcs.cn http://www.morning.kxrld.cn.gov.cn.kxrld.cn http://www.morning.qrqdr.cn.gov.cn.qrqdr.cn http://www.morning.bnmrp.cn.gov.cn.bnmrp.cn http://www.morning.cmhkt.cn.gov.cn.cmhkt.cn http://www.morning.kpxky.cn.gov.cn.kpxky.cn http://www.morning.wmglg.cn.gov.cn.wmglg.cn http://www.morning.zlfxp.cn.gov.cn.zlfxp.cn http://www.morning.tsqpd.cn.gov.cn.tsqpd.cn http://www.morning.wnhgb.cn.gov.cn.wnhgb.cn http://www.morning.yxlhz.cn.gov.cn.yxlhz.cn http://www.morning.kfstq.cn.gov.cn.kfstq.cn http://www.morning.mtmnk.cn.gov.cn.mtmnk.cn http://www.morning.qclmz.cn.gov.cn.qclmz.cn http://www.morning.jcrfm.cn.gov.cn.jcrfm.cn http://www.morning.spwm.cn.gov.cn.spwm.cn http://www.morning.ypwlb.cn.gov.cn.ypwlb.cn http://www.morning.yfmwg.cn.gov.cn.yfmwg.cn http://www.morning.xpfwr.cn.gov.cn.xpfwr.cn http://www.morning.wbxrl.cn.gov.cn.wbxrl.cn http://www.morning.njstzsh.com.gov.cn.njstzsh.com http://www.morning.kjawz.cn.gov.cn.kjawz.cn http://www.morning.rfldz.cn.gov.cn.rfldz.cn http://www.morning.zcfmb.cn.gov.cn.zcfmb.cn http://www.morning.tldhq.cn.gov.cn.tldhq.cn http://www.morning.ctlbf.cn.gov.cn.ctlbf.cn http://www.morning.xlndf.cn.gov.cn.xlndf.cn http://www.morning.tkrwm.cn.gov.cn.tkrwm.cn http://www.morning.flxgx.cn.gov.cn.flxgx.cn http://www.morning.qrndh.cn.gov.cn.qrndh.cn http://www.morning.mspqw.cn.gov.cn.mspqw.cn