Я пытаюсь сменить пароль в приведенном ниже фрагменте.Но когда я ввожу значения, никаких действий не происходит.У меня есть 3 поля:
1. current_password
2. new_password
3. re-enter_password.
Я использую залп.Я тестировал на отладчике значения равны нулю.Только условие if, где curr_pass.equals("")...
работает.как мне поступить?Ниже приведен весь фрагмент с инициализированными представлениями.
public class Change_password extends Fragment {
EditText current_pass,new_pass,re_enter_pass;
String curr_pass, newer_pass, re_pass,id;
Button changePwd_btn;
AlertDialog.Builder builder;
Session session;
String SP = "Name";
String url = "https://vendorapp.web4rest.com/VendorController/changePassword";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//returning our layout file
//change R.layout.yourlayoutfilename for each of your fragments
View v = inflater.inflate(R.layout.change_password, container, false);
builder = new AlertDialog.Builder(getContext());
current_pass = v.findViewById(R.id.current_pwd);
new_pass = v.findViewById(R.id.new_pwd);
re_enter_pass = v.findViewById(R.id.re_enter_pwd);
changePwd_btn = v.findViewById(R.id.change_pwd);
changePass();
return v;
}
changePwd_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ConnectivityManager ConnectionManager = (ConnectivityManager)getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = ConnectionManager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected() == true) {
curr_pass = current_pass.getText().toString();
newer_pass = new_pass.getText().toString();
re_pass = re_enter_pass.getText().toString();
if (curr_pass.equals("") || newer_pass.equals("") || re_pass.equals("")) {
builder.setTitle("Something went wrong!!");
displayAlert("Enter valid details");
}else{
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jobject = new JSONObject(response);
SharedPreferences preferences = getActivity().getSharedPreferences(SP, MODE_PRIVATE);
id = preferences.getString("ID", null);
if (Integer.parseInt(jobject.getString("status"))==200){
Toast.makeText(getContext(),"Password changed successfully!",Toast.LENGTH_SHORT).show();
session.setLoggedin(true);
getActivity().finish();
} else {
Toast.makeText(getContext(),jobject.getString("msg"),Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
Log.e("Error", "Login Failed" + e.toString());
e.printStackTrace();
Toast.makeText(getActivity(), "Error", Toast.LENGTH_SHORT);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Error", Toast.LENGTH_SHORT);
error.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> parmams = new HashMap<String, String>();
parmams.put("curr_pass", curr_pass);
parmams.put("new_pass", newer_pass);
parmams.put("user_id",id);
return parmams;
}
};
MySingleton.getInstance(getActivity()).addToRequestque(stringRequest);
}
}else {
Toast.makeText(getContext(), "Network Unavailable", Toast.LENGTH_LONG).show();
}
}
});
}