Skip to content

Instantly share code, notes, and snippets.

@codeguru42
Created April 13, 2014 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeguru42/10592863 to your computer and use it in GitHub Desktop.
Save codeguru42/10592863 to your computer and use it in GitHub Desktop.
onResume()
@Override
public void onResume() {
super.onResume();
// restore default header state
CheckedTextView headerCheck = (CheckedTextView) this.headerView
.findViewById(R.id.checkmark);
headerCheck.setChecked(false);
boolean[] newSelection = new boolean[this.adapter.getCount()];
if (this.savedSelection != null) {
// copy old selection array into new selection array
int numSelected = 0;
for (int i = 0; i < this.savedSelection.length; i++) {
newSelection[i] = this.savedSelection[i];
if (newSelection[i]) {
numSelected++;
}
View row = this.listView.getChildAt(i + 1);
if (row != null) {
CheckedTextView checkbox = (CheckedTextView) row
.findViewById(R.id.checkmark);
checkbox.setChecked(newSelection[i]);
TextView playerText = (TextView) row
.findViewById(R.id.player_name_text_view);
Log.d(TAG, playerText.getText().toString() + " checked? "
+ checkbox.isChecked());
}
}
// restore header state
if (numSelected == newSelection.length) {
headerCheck.setChecked(true);
}
}
// restore state
this.adapter.setSelection(newSelection);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment