Before this i just used string and integer only to set preferences. But now, i want set array. For example i want set value for index 0. setTotalValue[0] = 90; . Then i can get back using getTotalValue[0], so i will get value 90. Before this i used string , it much simple to me. This i show my code i make preference for string.
This class object
public class ShowDateFromTo {
private String fromDate;
public ShowDateFromTo(String fromDate) {
this.fromDate = fromDate;
}
public String getFromDate() {
return fromDate;
}
public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}
}
I change it to this one,
public class TotalBadge {
private ArrayList<Integer> totalValue = new ArrayList<Integer>();
public TotalBadge(ArrayList totalValue){
this.totalValue = totalValue;
}
public ArrayList<Integer> getTotalValue() {
return totalValue;
}
public void setTotalValue(ArrayList<Integer> totalValue) {
this.totalValue = totalValue;
}
}
Am i right ?
This class Preferences
public class PreferencesFromToDate {
SharedPreferences preferences;
public PreferencesFromToDate(Context context){
preferences = context.getSharedPreferences("pref", Context.MODE_PRIVATE);
}
public void setPreferencesFromToDate(ShowDateFromTo profiles){
SharedPreferences.Editor editor = preferences.edit();
editor.putString("FROMDATE",profiles.getFromDate());
editor.apply();
}
public ShowDateFromTo getPreferencesFromToDate(){
String fromDate = preferences.getString("FROMDATE", "");
ShowDateFromTo profiles = new ShowDateFromTo(fromDate);
profiles.setFromDate(fromDate);
return profiles;
}
}
This show i set it
ShowDateFromTo profile = new ShowDateFromTo(newdateFrom);
profile.setFromDate(newdateFrom);
How can i replace string with array. I have 4 index of array. Mean totalValue[0],totalValue[1],totalValue[2],totalValue[3]