gpt4 book ai didi

android - SupportPlaceAutocompleteFragment 的 OnPlaceSelectedListener 未在 ViewPager 内触发

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:27:33 27 4
gpt4 key购买 nike

我的应用程序有一个 viewPager 和 4 个 fragment 。在一个 fragment 中,我添加了一个 google SupportPlaceAutocompleteFragment

 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 从未触发,我无法获得所选地点的结果。取而代之的是被放置在第二个 fragment 中的 onActivityResults() 触发。我尝试在第一个 fragment 中使用 onActivityResults() 但它没有被触发,总是在第二个 fragment 中执行。

有什么想法吗?

最佳答案

来自 the docs :

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);
}

也许这就是解决方案。

关于android - SupportPlaceAutocompleteFragment 的 OnPlaceSelectedListener 未在 ViewPager 内触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34507708/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com