I have a shared_preference.xml
file Named as Item details
like this,
<map>
<string name="Product A">{"Item Name":"Product A","Item Total":"₹ 58.00"}</string>
<string name="Product B">{"Item Name":"Product B","Item Total":"₹ 63.00"}</string>
<string name="Product C">{"Item Name":"Product C","Item Total":"₹ 87.00"}</string>
<string name="Product D">{"Item Name":"Product D","Item Total":"₹ 74.00"}</string>
</map>
I want to get all values of Item Total
from this shared preference
even if i dont know the name of Product
.
Is there any way to get all the values by just giving the key
Item Total
.
Code used
private String getItemValue(String ProductName, String ValueName) {
SharedPreferences Prefs = this.getSharedPreferences("Item details", Context.MODE_PRIVATE);
Gson gson = new Gson();
String json = Prefs.getString(ProductName, "");
java.lang.reflect.Type type = new TypeToken<HashMap<String, Object>>() { }.getType();
HashMap<String, Object> obj = gson.fromJson(json, type);
return String.valueOf(obj.get(ValueName));
}