Methods Summary |
---|
protected void | onBindView(android.view.View view)
super.onBindView(view);
// Set our custom views inside the layout
final TextView myTextView = (TextView) view.findViewById(R.id.mypreference_widget);
if (myTextView != null) {
myTextView.setText(String.valueOf(mClickCounter));
}
|
protected void | onClick()
int newValue = mClickCounter + 1;
// Give the client a chance to ignore this change if they deem it
// invalid
if (!callChangeListener(newValue)) {
// They don't want the value to be set
return;
}
// Increment counter
mClickCounter = newValue;
// Save to persistent storage (this method will make sure this
// preference should be persistent, along with other useful checks)
persistInt(mClickCounter);
// Data has changed, notify so UI can be refreshed!
notifyChanged();
|
protected java.lang.Object | onGetDefaultValue(android.content.res.TypedArray a, int index)
// This preference type's value type is Integer, so we read the default
// value from the attributes as an Integer.
return a.getInteger(index, 0);
|
protected void | onRestoreInstanceState(android.os.Parcelable state)
if (!state.getClass().equals(SavedState.class)) {
// Didn't save state for us in onSaveInstanceState
super.onRestoreInstanceState(state);
return;
}
// Restore the instance state
SavedState myState = (SavedState) state;
super.onRestoreInstanceState(myState.getSuperState());
mClickCounter = myState.clickCounter;
notifyChanged();
|
protected android.os.Parcelable | onSaveInstanceState()
/*
* Suppose a client uses this preference type without persisting. We
* must save the instance state so it is able to, for example, survive
* orientation changes.
*/
final Parcelable superState = super.onSaveInstanceState();
if (isPersistent()) {
// No need to save instance state since it's persistent
return superState;
}
// Save the instance state
final SavedState myState = new SavedState(superState);
myState.clickCounter = mClickCounter;
return myState;
|
protected void | onSetInitialValue(boolean restoreValue, java.lang.Object defaultValue)
if (restoreValue) {
// Restore state
mClickCounter = getPersistedInt(mClickCounter);
} else {
// Set state
int value = (Integer) defaultValue;
mClickCounter = value;
persistInt(value);
}
|