Android 类FragmentResultListener,错误找不到符号
我正面临一个我不明白的问题。玩碎片游戏,并试图从我的第二个碎片到第一个碎片中获得结果。我得到一个关于“FragmentResultListener”的编译错误 我使用的是由提出的代码。 代码如下:Android 类FragmentResultListener,错误找不到符号,android,fragment,Android,Fragment,我正面临一个我不明白的问题。玩碎片游戏,并试图从我的第二个碎片到第一个碎片中获得结果。我得到一个关于“FragmentResultListener”的编译错误 我使用的是由提出的代码。 代码如下: public class FirstFragment extends ListFragment { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate
public class FirstFragment extends ListFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentResultListener a = new FragmentResultListener() { } ;
getParentFragmentManager().setFragmentResultListener("key", this, new FragmentResultListener() {
@Override
public void onFragmentResult(@NonNull String key, @NonNull Bundle bundle) {
// We use a String here, but any type that can be put in a Bundle is supported
String result = bundle.getString("bundleKey");
// Do something with the result...
}
});
}
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState
) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_first, container, false);
}
...
我从2020年5月20日开始使用安卓4.0
非常感谢你的帮助
FredFred,我在更新androidx时遇到了这个问题。导航:导航组合:1.0.0-alpha08到1.0.0-alpha09。我不得不回到以前的版本,文档似乎还没有更新以通知该方法的消失。Fred,我在更新androidx时遇到了这个问题。导航:导航组合:1.0.0-alpha08到1.0.0-alpha09。我不得不回到以前的版本,文档似乎还没有更新以告知该方法的消失。非常感谢您的帮助非常感谢您的帮助
public class FirstFragment extends ListFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentResultListener a = new FragmentResultListener() { } ;
getParentFragmentManager().setFragmentResultListener("key", this, new FragmentResultListener() {
@Override
public void onFragmentResult(@NonNull String key, @NonNull Bundle bundle) {
// We use a String here, but any type that can be put in a Bundle is supported
String result = bundle.getString("bundleKey");
// Do something with the result...
}
});
}
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState
) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_first, container, false);
}
...