0
我發佈的Json對象數據在我的應用程序中使用排球庫,但我想從該請求獲取響應並根據響應更新UI,並在執行後臺進程時顯示progressdialog process.how我可以這樣做嗎,請告訴我。如何從json中使用排序響應android
這裏是我的代碼: -
public void postData() {
try {
getText();// get Input Text by the user
String json;// storing json object
JSONObject jsonObject = new JSONObject();
jsonObject.put("agentCode", s_szMobileNumber);
jsonObject.put("pin", s_szOldPassword);
jsonObject.put("newpin", s_szNewPassword);
// 4. convert JSONObject to JSON to String
json = jsonObject.toString();
System.out.println("Server Request:-" + json);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, CServerAPI.s_szChangePassUrl, jsonObject, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonObjectRequest);
} catch (Exception e) {
e.printStackTrace();
}
}
public void getText() {// getting text from editText.....
s_szMobileNumber = m_MobileEditText.getText().toString().trim();// get mobile number from edit text
s_szNewPassword = m_NewPassEditText.getText().toString().trim();// get new pasword from edit Text
}
public void getResponse() throws JSONException {// method regarding condition.................
if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Transaction Successful")) {
s_szResponseNewPassword = m_oResponseobject.getString("newpin");// getting new password response from server....
CSnackBar.getInstance().showSnackBarSuccess(findViewById(R.id.mainLayout), "Password Changed Successfully", getApplicationContext());
upDatePassword();// updating password in shared preference.......
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent login = new Intent(getApplicationContext(), CLoginScreen.class);
startActivity(login);
}
}, 3500);
} else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Subscriber/Agent Not Found")) {
CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "User not found", getApplicationContext());
} else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("New Pin Can Not Be Empty")) {
CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "Enter valid password", getApplicationContext());
} else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Pin Can Not Be Empty")) {
CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "Old pin not found", getApplicationContext());
} else if (m_oResponseobject.getString("resultdescription").equalsIgnoreCase("Agentcode Can Not Be Empty")) {
CSnackBar.getInstance().showSnackBarError(findViewById(R.id.mainLayout), "Enter valid mobile number", getApplicationContext());
}
}
public void upDatePassword() {// Update old password from new password in shared preference ......
m_Preferences = getApplicationContext().getSharedPreferences("LoginData", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = m_Preferences.edit();
editor.putString("pin", s_szResponseNewPassword);
editor.apply();
}
但如何讓狀態如前所述 – Nitin