我在容器類裏面有這個函數(下面),我想改變一個的裏面的容器類的變量值(fbresponse
),我該怎麼做?如何將內部類(Response.Listener)的變量值保存到外部?
private void facebookCheckEmail(String email) {
fbCheckEmail_params = new HashMap<String, String>();
fbCheckEmail_params.put("Email", email);
final GsonRequest<FbCheckObject> gsonRequest = ApiRequest.gsonFacebookCheckEmailRequest
(
new Response.Listener<FbCheckObject>() {
@Override
public void onResponse(FbCheckObject fbCheckObject) {
try {
System.out.println("Status = " + fbCheckObject.getStatus());
if (new String(fbCheckObject.getStatus()).equals("ok") == true) {
fbresponse = "ok";
} else if(new String(fbCheckObject.getStatus()).equals("no") == true){
fbresponse = "no";
}
} catch (Exception e) {
Log.d("Web Service Error", e.getMessage());
e.printStackTrace();
}
}
}
,
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Deal with the error here
}
},
fbCheckEmail_params
);
AppController.getInstance().addToRequestQueue(gsonRequest, TAG);
}
我的容器類是:
public class MainLoginActivity extends Activity {
public String fbresponse = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
.......
}
..........
private void facebookCheckEmail(String email) {
......
}
}
注意:裏面的「@Override public void onResponse(FbCheckObject fbCheckObject) {}
」,fbresponse
值被成功分配到「ok
」或「no
」如果不成功,但任何地方,範圍之外,如果我System.out.printIn
fbresponse
,我會得到「null
」
你做改變變量,據我可以看到。還是不編譯?什麼是不按預期工作 – zapl
當我System.out.println()fbresponse新的Response.Listener(){}範圍它返回「null」 –
yeh
代碼示例中缺少的東西。您正在爲變量分配一個空白,然後將其更改爲「ok」或「no」。我沒有看到NULL應該分配給變量。 – tak3shi