怎么给fragment构造参数
答案:2 悬赏:0
解决时间 2021-02-15 13:12
- 提问者网友:枯希心
- 2021-02-15 01:41
怎么给fragment构造参数
最佳答案
- 二级知识专家网友:时光不老我们不分离
- 2021-02-15 02:59
正常的使用一切都是正常,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后发现
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后发现
全部回答
- 1楼网友:深街酒徒
- 2021-02-15 03:12
正常的使用一切都是正常,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
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯