I am trying to change the value in shared Preference when I change the value Quantity of number in Edit Text, but it cannot be replace the value in shared preference instead of stored separately in shared preference.
Code:
JSONArray test = new JSONArray();
JSONArray test1 = new JSONArray();
JSONArray test2 = new JSONArray();
JSONArray items = null;
JSONArray itemsQty = null;
test1.put("0");
test2.put("0");
test.put(test1);
test.put(test2);
JSONArray listitems = null;
String Sharedqty = String.valueOf(cartlistadp.get(getAdapterPosition()).getQty());
String channel = (shared.getString(Constants.cartid, String.valueOf(test)));
if (TextUtils.isEmpty(channel)) {
try {
listitems = new JSONArray(channel);
itemsQty = listitems.getJSONArray(1);
} catch (JSONException e) {
e.printStackTrace();
}
for (int x = 0; x < itemsQty.length(); x++) {
if (itemsQty.equals(qtyString)) {
try {
listitems.getJSONArray(1).put(String.valueOf(qtyString));
} catch (JSONException e) {
e.printStackTrace();
}
}
QutId.putString(Constants.cartid,
(String.valueOf(listitems)));
QutId.apply();
}
}
Note: I used this code in EditText TextWatcher
I can't replace the value,anyone can solve this problem
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire