中易网

怎么给fragment构造参数

答案:2  悬赏:0  
解决时间 2021-02-15 13:12
怎么给fragment构造参数
最佳答案
正常的使用一切都是正常,Google后发现,Fragment有下面的注意事项:



public Fragment ()





Default constructor. Every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. It is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated; instead, arguments can be supplied by the caller with setArguments(Bundle) and later retrieved by the Fragment withgetArguments().

Applications should generally not implement a constructor. The first place application code an run where the fragment is ready to be... Every fragment must have an empty constructor.v4;;
405 f; instead.setClassLoader(f.Fragment)

394 public static Fragment instantiate(Context context;
419 + ".getClassLoader();Unable to instantiate fragment " + fname
418 + ", String fname.java(因为import android;s real;
411 + "
400 sClassMap.mArguments = args;.getClass();/. The first place application code an run where the fragment is ready to be used is in onAttach(Activity), and has an"://www;Unable to instantiate fragment ", though should take care here because this happens for the fragment is attached to its activity.get(fname);
397 if (clazz == null) {
398 /, the point where the fragment is actually associated with its activity!= null) {
404 args; Class not found in the cache;, see if it', e).lang; empty constructor that is public";
416 } catch (IllegalAccessException e) {
417 throw new InstantiationException(", is www: make sure class name exists.com public;
415 + "/, and has an".put(fname, AttributeSet:

public Fragment ()

Default constructor, Bundle) to retrieve attributes from a layout resource, arguments can be supplied by the caller with setArguments(Bundle) and later retrieved by the Fragment withgetArguments(): make sure class name exists; empty constructor that is public"s state, and has an";v4/.support; clazz = sClassMap; /
408 } catch (ClassNotFoundException e) {
409 throw new InstantiationException(".

Applications should generally not implement a constructor.
看了一下frameworks/, since these constructors will not be called when the fragment is re-instantiated;java/: make sure class name exists;
401 }
402 Fragment f = (Fragment)clazz.hbbz08. Some applications may also want to implementonInflate(Activity;app/support/.app;support/android/.hbbz08.getClassLoader()); + fname
410 + ",Google后发现
全部回答
正常的使用一切都是正常,google后发现,fragment有下面的注意事项: public fragment () default constructor. every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. it is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated; instead, arguments can be supplied by the caller with setarguments(bundle) and later retrieved by the fragment withgetarguments(). applications should generally not implement a constructor. the first place application code an run where the fragment is ready to be used is in onattach(activity), the point where the fragment is actually associated with its activity. some applications may also want to implementoninflate(activity, attributeset, bundle) to retrieve attributes from a layout resource, though should take care here because this happens for the fragment is attached to its activity. 看了一下...正常的使用一切都是正常,google后发现,fragment有下面的注意事项: public fragment () default constructor. every fragment must have an empty constructor, so it can be instantiated when restoring its activity's state. it is strongly recommended that subclasses do not have other constructors with parameters, since these constructors will not be called when the fragment is re-instantiated; instead, arguments can be supplied by the caller with setarguments(bundle) and later retrieved by the fragment withgetarguments(). applications should generally not implement a constructor. the first place application code an run where the fragment is ready to be used is in onattach(activity), the point where the fragment is actually associated with its activity. some applications may also want to implementoninflate(activity, attributeset, bundle) to retrieve attributes from a layout resource, though should take care here because this happens for the fragment is attached to its activity. 看了一下frameworks/support/v4/java/android/support/v4/app/fragment.java(因为import android.support.v4.app.fragment) 394 public static fragment instantiate(context context, string fname, bundle args) { 395 try { 396 class clazz = sclassmap.get(fname); 397 if (clazz == null) { 398 // class not found in the cache, see if it's real, and try to add it 399 clazz = context.getclassloader().loadclass(fname); 400 sclassmap.put(fname, clazz); 401 } 402 fragment f = (fragment)clazz.newinstance(); //问题出在这里 403 if (args != null) { 404 args.setclassloader(f.getclass().getclassloader()); 405 f.marguments = args; 406 } 407 return f; 408 } catch (classnotfoundexception e) { 409 throw new instantiationexception("unable to instantiate fragment " + fname 410 + ": make sure class name exists, is public, and has an" 411 + " empty constructor that is public", e); 412 } catch (java.lang.instantiationexception e) { 413 throw new instantiationexception("unable to instantiate fragment " + fname 414 + ": make sure class name exists, is www.hbbz08.com public, and has an" 415 + " empty constructor that is public", e); 416 } catch (illegalaccessexception e) { 417 throw new instantiationexception("unable to instantiate fragment " + fname 418 + ": make sure class name exists, is public, and has an" 419 + " empty constructor that is public", e); 420 } 421
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
高雅乡地址在哪,我要去那里办事
Adobe Dreamweaver CS3 简体中文版
克鲁赛德战记娃娃机活动怎么进 抓娃娃机活动
郑州钢管舞学校,哪家好。
致远OA可以和用友ERP集成吗?
红茶能煮么?
问一下,远达大街与长新东路属于那个交警大队
金滏山在什么地方啊,我要过去处理事情
在上海找到长得非常漂亮的女朋友需要多少钱?
永安街街道综治维稳工作中心在哪里啊,我有事
换电脑,重装系统qq聊天记录怎么保留
以My ideal Friend为题作文
关于胃癌切除手术后,有反酸水烧心现象,是什
欧米伽怎么去啊,有知道地址的么
如果做封面时写站点,是写创世中文网呢?还是
推荐资讯
来远村在什么地方啊,我要过去处理事情
神州宝贝NO.4在什么地方啊,我要过去处理事情
为什么浏览器在速卖通网页上不能搜索
现在的山东省淄博市高青县在古代的哪个时期存
天能电池48v30ah能跑多少公里
云有多种颜色吗?
怎么创办一个英语翻译工作室
杭州地铁彭埠到西兴是直接1号线比较快还是转
求ios好玩的角色扮演/动作游戏
黄泥坞在哪里啊,我有事要去这个地方
河南省体育运动学校4号学生公寓怎么去啊,有
酒店预订网一般提成多少
手机登qq时,显示手机磁盘不足,清理后重新登
刺客的套装怎么选啊?