Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何获取函数外部的回调值_Android_Android Volley - Fatal编程技术网

Android 如何获取函数外部的回调值

Android 如何获取函数外部的回调值,android,android-volley,Android,Android Volley,我正在使用volley库并进行回调,但在回调中得到结果之后。如何将其分配给另一个变量并在同一活动中使用 IResult getResult = new IResult() { @Override public void notifySuccess(String requestType, String response) { } @Override public void notif

我正在使用volley库并进行回调,但在回调中得到结果之后。如何将其分配给另一个变量并在同一活动中使用

IResult getResult = new IResult() 

 {      @Override
            public void notifySuccess(String requestType, String response) {

            }

            @Override
            public void notifyError(String requestType, VolleyError error) {

            }
        };


您可以在活动中定义变量并从回调中分配它。 如果您想从此结果更新视图,可以从结果回调调用方法

 String apiResult=null;  

    IResult getResult = new IResult() 

     {      @Override
                public void notifySuccess(String requestType, String response) {
                  apiResult=response
                  //or call method for update UI
                }

                @Override
                public void notifyError(String requestType, VolleyError error) {
                  //or call method for update UI
                }
            };

希望这对你有帮助

在notifySuccess中全局声明变量并直接赋值。或者编写函数并将响应作为参数发送给该函数,并在函数中分配变量。我也做了同样的事情,但当我检查Logcat时。我没有得到变量中的响应。请使用用于显示的代码更新您的问题,以及plz添加来自响应的json响应。