代码:
public PlacePickerFragment() {
this(null);
}
public PlacePickerFragment(Bundle args) {
super(GraphPlace.class, R.layout.com_facebook_placepickerfragment, args);
setPlacePickerSettingsFromBundle(args);
}
您好,我想从上面的代码中删除弃用警告,有没有办法将其更改为默认构造函数?
最佳答案
创建 fragment 时,使用 setArgument():
Bundle args = new Bundle();
// Construct your bundle here
Fragment mFragment = new PlacePickerFragment();
mFragment.setArguments(args);
mFragment.initialize();
并使用 fragment 的默认构造函数。您可能需要在设置参数后调用 setPlacePickerSettingsFromBundle()
,如下所示:
public PlacePickerFragment() {
super(GraphPlace.class, R.layout.com_facebook_placepickerfragment, args);
}
public void initialize() {
Bundle args = getArguments();
setPlacePickerSettingsFromBundle(args);
}
关于java - 如何将 fragment 中的非默认构造函数更改为默认构造函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13485767/