【问题标题】:NOt returning to fragment after a web service call to load images在 Web 服务调用加载图像后不返回片段
【发布时间】:2016-02-01 22:58:17
【问题描述】:

下面是我用来填充图像的片段

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    Log.i(TAG, "onCreateView");

    Bundle bundle = this.getArguments();

    View inflatedView                   = inflater.inflate(R.layout.fragment_picture_grid, container, false);

    this.gridView                       = (GridView) inflatedView.findViewById(R.id.gridview);
    this.myImageAdapater                = new DeviceImageAdapter(this.getActivity(), bundle.getString("id"), bundle.getString("name"));

我正在使用自定义适配器来设置网格视图,并编写了某些方法来调用 Web 服务。从 web 服务收到响应后,我不会返回调用片段。请帮忙。我是安卓开发新手。

【问题讨论】:

  • 如果您永远不会从DeviceImageAdapter 返回,那么该类中可能存在一些错误。您在 logcat 上收到任何崩溃或消息吗?你能提供那个类的代码吗?对了,你是把适配器设置为GridView吗?
  • 是的,我正在设置适配器
  • 我正在从 DEviceImage 适配器类调用一个 web 服务,然后我得到了结果。
  • 我在日志中看到,即使在我得到响应之前,我也会来回移动到片段,最后在收到响应时移动到主要活动
  • 没有代码真的很难说哪里出了问题。你能提供吗?

标签: android web-services gridview imageview


【解决方案1】:

我的问题是收到 Web 服务响应后没有调用该片段。对于我发现的解决方法是:

  1. 将 Fragment 和 gridview 作为参数传递给自定义适配器。
  2. 一旦我收到来自网络服务器的响应,我将调用一个应该在收到响应后执行的方法,并将片段和网格视图传递给它。

我也不知道它是否是最好的解决方案,但它的工作原理..:)

【讨论】:

    猜你喜欢
    • 2019-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多