Preference、PreferenceActivity,PreferenceFragment
Preference的容器,如PreferenceGroup持有一个ListView对象成员,而adapter是PreferenceGroupAdapter(extends BaseAdapter)
PreferenceGroupAdapter
#getView()
public View getView(int position, View convertView, ViewGroup parent) {
final Preference preference = this.getItem(position);//获取对应的Preference
// Build a PreferenceLayout to compare with known ones that are cacheable.
mTempPreferenceLayout = createPreferenceLayout(preference, mTempPreferenceLayout);
// If it's not one of the cached ones, set the convertView to null so that
// the layout gets re-created by the Preference.
if (Collections.binarySearch(mPreferenceLayouts, mTempPreferenceLayout) < 0 ||
(getItemViewType(position) == getHighlightItemViewType())) {
convertView = null;
}
View result = preference.getView(convertView, parent);//调用Preference的getView获取view
if (position == mHighlightedPosition && mHighlightedDrawable != null) {
ViewGroup wrapper = new FrameLayout(parent.getContext());
wrapper.setLayoutParams(sWrapperLayoutParams);
wrapper.setBackgroundDrawable(mHighlightedDrawable);
wrapper.addView(result);
result = wrapper;
}
return result;
}
Preference#getView()
/**
* Gets the View that will be shown in the {@link PreferenceActivity}.
*
* @param convertView The old View to reuse, if possible. Note: You should
* check that this View is non-null and of an appropriate type
* before using. If it is not possible to convert this View to
* display the correct data, this method can create a new View.
* @param parent The parent that this View will eventually be attached to.
* @return Returns the same Preference object, for chaining multiple calls
* into a single statement.
* @see #onCreateView(ViewGroup)
* @see #onBindView(View)
*/
public View getView(View convertView, ViewGroup parent) {
if (convertView =