SupportPlaceAutocompleteFragment 的 OnPlaceSelectedListener 未触发

2023-12-01

我遇到了问题OnPlaceSelected监听器的方法支持地点自动完成片段.

My onViewCreated() method:

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // Initialise a new fragment inside of this one.
    mFragmentManager = getChildFragmentManager();
    mSupportMapFragment = (SupportMapFragment) mFragmentManager.findFragmentByTag("mapFragment");
    mSupportPlaceAutocompleteFragment = (SupportPlaceAutocompleteFragment) mFragmentManager.findFragmentByTag("autocompleteFragment");

    // Never inflate fragments inside other fragments in a layout.xml!
    // Do it programmatically.
    // See here for reference: https://stackoverflow.com/a/19815266/4938112.
    if (mSupportMapFragment == null) {
        mSupportMapFragment = new SupportMapFragment();
        fragmentTransaction(mFragmentManager, mSupportMapFragment, R.id.map_fragment_container, "mapFragment");
    }

    // Asynchronous thread to load map.
    mSupportMapFragment.getMapAsync(this);


    if (mSupportPlaceAutocompleteFragment == null) {
        mSupportPlaceAutocompleteFragment = new SupportPlaceAutocompleteFragment();
        fragmentTransaction(mFragmentManager, mSupportPlaceAutocompleteFragment, R.id.card_view, "autocompleteFragment");
    }

    // Filter for a specific place type.
    AutocompleteFilter typeFilter = new AutocompleteFilter.Builder()
            .setTypeFilter(AutocompleteFilter.TYPE_FILTER_CITIES)
            .build();
    mSupportPlaceAutocompleteFragment.setFilter(typeFilter);

    Log.d("I'M HERE", "Hello.");

    mSupportPlaceAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
        @Override
        public void onPlaceSelected(Place place) {
            // TODO: Get info about the selected place.
            Log.i("PLACE", "Place: " + place.getName());
            int flag = 1;
            Log.d("FLAG", "flag: " + flag);
        }

        @Override
        public void onError(Status status) {
            // TODO: Handle the error.
            Log.i("PLACE_ERROR", "An error occurred: " + status);
            int flag = 0;
            Log.d("FLAG", "flag: " + flag);
        }
    });

    Log.d("I'M HERE, TOO", "Hello.");

}

当我选择一个地点(所有 API 均已启用并且我有 Google Key)时,AutoCompleteFragment 只是关闭,地图上没有任何反应。 这mSupportPlaceAutocompleteFragment.setOnPlaceSelectedListener(...)方法没有被解雇。

有什么提示吗?

我的问题与中的问题类似这个问题.

我也在使用嵌套片段,但我不明白如何查看onActivityResult()本例中的方法。


终于解决了这个问题:希望它能帮助别人。

我在中添加了这句臭名昭著的行onActivityResult()我的 MainActivity 中的方法

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

    ...
}

然后在我的 MapFragment 中放入相同的方法

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

现在嵌套片段正在发送回其数据。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

SupportPlaceAutocompleteFragment 的 OnPlaceSelectedListener 未触发 的相关文章

随机推荐

  • 使用服务帐户在 NodeJS 上设置 Google Drive API

    我正在尝试使用服务帐户通过 NodeJS 服务器连接到 Google Drive API 目标是让服务器能够以服务帐户身份进行身份验证 从驱动器检索相关文件并将其发送回用户 而无需用户直接登录 Google 这将使我能够通过网络应用程序控制
  • 为什么链码实例化成功,但查询失败[重复]

    这个问题在这里已经有答案了 peer chaincode install n simple token v 1 0 l java p Users friends Documents Virtual Machines localized sh
  • printf() 中的 e 格式和精度修饰符

    你能解释一下为什么吗 printf 2 2e 1201 0 给出一个结果1 20e 03不仅仅是12 01e2 我的想法 默认数字是1201 0 说明符告诉数字后面应该有2个数字 怎么了 根据维基百科 In normalized scien
  • 查看 VSTF 构建上的 git-lfs 文件

    我有一个托管在 VSTS 上的存储库 其中包含通过 git lfs 存储的文件 如果我只是让 VSTS 构建签出存储库 它只会下载包含文件 ID 的 git lfs 元数据文件 以下是 VSTS 如何获取其源的输出 Syncing repo
  • 耙子中止! JSON::GeneratorError: rake asset:precompile 后源序列非法/格式错误 utf-8

    我完成了一个网站的构建 并希望将其部署到 Digital Ocean VPN 安装了 Capistrano 和 Passenger 在初始部署期间 我收到了一个显然与预编译资产有关的错误 因此我在本地 Rails 生产环境中尝试了 rake
  • 当用户按下home键并再次双击返回时会调用哪些方法

    我想知道当用户按下主页按钮并再次双击以返回我的应用程序时会调用哪些方法 事件 applicationDidEnterBackground applicationWillEnterForeground 这些都在应用程序委托中调用 所有详细信息
  • 运行 byfn 时出错:无法认可链码安装,rpc 错误代码不可用

    我在 CentOS 7 上 安装了所有先决条件 克隆了 Fabric samples git 存储库 我指的是教程 Building Your First Network 发现here 至此我已经成功运行命令了 byfn sh genera
  • 如何理解Ruby的.each和.map

    我无法理解之间的差异map and each 以及何时何地使用它们 我读 地图有什么作用 and Ruby 迭代器 但想要一些澄清 如果我有 z 1 2 3 map x x 1 map获取数组中的每个元素z并向每个元素添加一个 但是它不会改
  • Swift:当用户在 UITextView 中键入时连续调整 tableViewCell 的大小

    介绍 Context 我正在创建我的第一个应用程序 但遇到了一个我无法解决的问题 我有 tableView 其中的单元格中填充了相当多的 UIElements 所有约束都是使用 EasyPeasy 库完成的 它基本上只是设置自动布局约束 我
  • 脚本不适用于匿名用户、Google 电子表格

    我目前正在编辑一个 Google 电子表格 该电子表格设置为供登录和匿名用户公开编辑 我不是所有者 我在电子表格中创建了一个脚本并将其分配给一个绘图 插入绘图 我还为图像分配了脚本 有两个不幸的奇怪现象 1 如果您是匿名的 则不会出现绘图
  • 如何测量代码的内存使用情况?

    我正在尝试测量代码的内存使用情况 但我不知道如何继续 我不想使用 DotMemory 或任何我需要通过编程来完成的 分析器 有什么方法可以知道分配了多少对象 就像 5 int 4 字节 4 Object 16 字节 I used 流程 Wo
  • Angular 2 中的背景图像

    如何通过ngOnInit添加图片到背景 我不想使用background url link of my image 在 CSS 中 因为这会增加我网站的负载 我想通过 Angular 2 Typescript 来做到这一点 在您的 compo
  • 替换全局变量,如何以及为什么

    好的 到目前为止我已经工作并使用了全局变量 并且仅调用 USER 来获取用户 ID 没有问题 大多数时候 人们对 SO 的看法以及一些到处阅读的文章都对使用全局变量持负面态度 所以现在我准备改变方式而不是使用全局变量 现在我包含一个函数 p
  • 将 HashMap 放入 jsonobject

    我构建一个 json 对象 该对象由 Hashmap 中定义的 nameValue 对组成 我遇到的问题是当我调用时 jsonObject put hashmap 它添加 nameValue 对 如下所示 name value代替name
  • CUDA + OpenGL 互操作,不带已弃用的功能

    我之前已经能够通过以下方式在 CUDA 中填充纹理以在 OpenGL 中使用 创建并初始化 GL 纹理 gl GenTextures etc 创建 GL 像素缓冲区对象 向 CUDA 注册 PBO 在更新 渲染循环中 cudaGraphic
  • 尝试将yield理解为一个表达式

    我正在摆弄生成器和生成器表达式 但我不完全确定我理解它们是如何工作的 一些参考资料 gt gt gt a x for x in range 10 gt gt gt next a 0 gt gt gt next a 1 gt gt gt a
  • 如何切换到 Coq 的特定版本——尤其是在使用 Opam 管理 Coq 版本时?

    我目前使用的是标准方式 可能通过网站 安装的标准方式 但我想用tcoq 我相信我已经正确安装了它 因为我有一个 bin 文件 并且所有常见的 Coq 内容似乎都在那里 pinno gamepad tcoq ls bin coq tex co
  • 脚本仅在页面重新加载时工作

    我正在使用 jQuery 在水平视图网站上对齐图像 但该脚本仅在我重新加载页面时才起作用 http joliannelm steveforest com edition roux de service html 该脚本在之前被调用 这是脚本
  • Node.js 生成子进程并实时获取终端输出

    我有一个脚本 输出 hi 休眠一秒 输出 hi 休眠 1 秒 依此类推 现在我想我可以用这个模型来解决这个问题 var spawn require child process spawn temp spawn PATH TO SCRIPT
  • SupportPlaceAutocompleteFragment 的 OnPlaceSelectedListener 未触发

    我遇到了问题OnPlaceSelected监听器的方法支持地点自动完成片段 My onViewCreated method Override public void onViewCreated View view Bundle savedI