ViewPager内未触发SupportPlaceAutocompleteFragment的OnPlaceSelectedListener [英] OnPlaceSelectedListener of SupportPlaceAutocompleteFragment not fired inside ViewPager

查看:88
本文介绍了ViewPager内未触发SupportPlaceAutocompleteFragment的OnPlaceSelectedListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序具有一个viewPager和4个片段,并且处于活动状态. 在一个片段中,我添加了一个Google SupportPlaceAutocompleteFragment

My application has and activity with a viewPager and 4 fragments. In one fragment I added a google SupportPlaceAutocompleteFragment and

 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.area_swipe_fragment, container, false);



    SupportPlaceAutocompleteFragment autocompleteFragment = (SupportPlaceAutocompleteFragment)
            getChildFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

    autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            Toast.makeText(ctx, "do something", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(Status status) {
        }
    });






    return view;
}

我的问题是onPlaceSelectedListener从未触发过,我无法获得所选位置的结果.相反,将其解雇放置在第二个片段中的onActivityResults(). 我尝试在第一个片段中使用onActivityResults(),但不会被触发,请始终在第二个片段中执行该操作.

My problem is the onPlaceSelectedListener is never fired and I can't get the result of the selected place. Instead get fired the onActivityResults() placed in the second fragment. I tried with a onActivityResults() in the first fragment but it doesn't get fired, always executed the one in the second fragment.

有什么想法吗?

推荐答案

来自文档:

如果您的片段嵌套在另一个片段中,则您的应用还必须 将onActivityResult()调用转发到包含的片段,如图所示 在以下代码段中:

If your fragment is nested within another fragment, your app must also forward onActivityResult() calls to the containing fragment, as shown in the following snippet:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    autocompleteFragment.onActivityResult(requestCode, resultCode, data);
}

也许这就是解决方案.

这篇关于ViewPager内未触发SupportPlaceAutocompleteFragment的OnPlaceSelectedListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆