Dynamically save the button_id which are clicked in shared pref. You have already done everything, you need to restore button state from you shared pref and when you are clicking any button add the button in the shared pref.
Update:
public static final String PREFS_NAME = "MyPrefsFile";
------
final Button next = (Button) layout.findViewById(R.id.next_button);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean isClicked = settings.getBoolean(getCurrentItemPosition(), false);
if(isClicked)
{
next.setBackgroundColor(0xffeeeeee);
}
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
int j = getItem(+1) + 1;
Toast.makeText(context, context.getResources().getString(R.string.question_no) + " " + j, Toast.LENGTH_SHORT).show();
pager.setCurrentItem(getItem(+1), true);
// i need to save this new bacground color
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean(getCurrentItemPosition(), true);
editor.commit();
}
private int getItem(int i) {
return i += pager.getCurrentItem();
}
});
getCurrentItemPosition()
is the current itemposition.