You can use the below code for shared preferences.
public class WebService {
String PREF_NAME = "PREF_NAME";
public static SharedPreferences sp;
Editor spEdit;
public String UserID;
public String Password;
public LoginWebService(Context ctx) {
// TODO Auto-geneated constructor stub
sp = ctx.getSharedPreferences(PREF_NAME, 0);
spEdit = sp.edit();
}
public void setUserID(String UserID) {
spEdit.putString("UserID", UserID);
spEdit.commit();
}
public String getUserID() {
return sp.getString("UserID", "");
}
public String getPassword() {
return sp.getString("Password", "");
}
public void setPassword(String Password) {
spEdit.putString("Password", Password);
spEdit.commit();
}
public void clear(){
spEdit.clear();
spEdit.commit();
}
}
While saving the data in the shared preferences you can use like below.
WebService objlogin=new WebService(context);
objlogin.clear();
for (int i = 0; i <arraylist.size(); i++)
{
objlogin.setUserID(arraylist.get(i).something);
objlogin.setPassword(arraylist.get(i).something);
}
Then you all the data's will be saved in the shard preferences.
Hope this will help you.