diff options
author | Andrew Stadler <stadler@android.com> | 2010-08-17 16:16:42 -0700 |
---|---|---|
committer | Andrew Stadler <stadler@android.com> | 2010-08-17 16:16:42 -0700 |
commit | 468c3230dafc2d131bdeded7b5a6825988166244 (patch) | |
tree | f55f7bbd08c5046a23d2f42862743295330ee597 /core | |
parent | 6394c0e52cf641d93f678fd052499aa952e3595d (diff) | |
download | frameworks_base-468c3230dafc2d131bdeded7b5a6825988166244.zip frameworks_base-468c3230dafc2d131bdeded7b5a6825988166244.tar.gz frameworks_base-468c3230dafc2d131bdeded7b5a6825988166244.tar.bz2 |
Fix two bugs in PreferenceActivity headers
* Make Header fields public so activities can write them
* Recycle views properly
* Also made the HeaderAdapter and HeaderViewHolder static inner classes
for a little extra efficiency.
Change-Id: If0a9276e4609e2e8568c7c5a6963f3ed3e25565f
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/preference/PreferenceActivity.java | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/core/java/android/preference/PreferenceActivity.java b/core/java/android/preference/PreferenceActivity.java index 6b00690..03fc399 100644 --- a/core/java/android/preference/PreferenceActivity.java +++ b/core/java/android/preference/PreferenceActivity.java @@ -194,13 +194,13 @@ public abstract class PreferenceActivity extends ListActivity implements } }; - private class HeaderViewHolder { - ImageView icon; - TextView title; - TextView summary; - } + private static class HeaderAdapter extends ArrayAdapter<Header> { + private static class HeaderViewHolder { + ImageView icon; + TextView title; + TextView summary; + } - private class HeaderAdapter extends ArrayAdapter<Header> { private LayoutInflater mInflater; public HeaderAdapter(Context context, List<Header> objects) { @@ -217,23 +217,31 @@ public abstract class PreferenceActivity extends ListActivity implements view = mInflater.inflate(com.android.internal.R.layout.preference_list_item, parent, false); holder = new HeaderViewHolder(); - holder.icon = (ImageView)view.findViewById( - com.android.internal.R.id.icon); - holder.title = (TextView)view.findViewById( - com.android.internal.R.id.title); - holder.summary = (TextView)view.findViewById( - com.android.internal.R.id.summary); + holder.icon = (ImageView) view.findViewById(com.android.internal.R.id.icon); + holder.title = (TextView) view.findViewById(com.android.internal.R.id.title); + holder.summary = (TextView) view.findViewById(com.android.internal.R.id.summary); view.setTag(holder); } else { view = convertView; - holder = (HeaderViewHolder)view.getTag(); + holder = (HeaderViewHolder) view.getTag(); } + // All view fields must be updated every time, because the view may be recycled Header header = getItem(position); - if (header.icon != null) holder.icon.setImageDrawable(header.icon); - else if (header.iconRes != 0) holder.icon.setImageResource(header.iconRes); - if (header.title != null) holder.title.setText(header.title); - if (header.summary != null) holder.summary.setText(header.summary); + if (header.icon == null) { + holder.icon.setImageDrawable(null); + holder.icon.setImageResource(header.iconRes); + } else { + holder.icon.setImageResource(0); + holder.icon.setImageDrawable(header.icon); + } + holder.title.setText(header.title); + if (TextUtils.isEmpty(header.summary)) { + holder.summary.setVisibility(View.GONE); + } else { + holder.summary.setVisibility(View.VISIBLE); + holder.summary.setText(header.summary); + } return view; } @@ -247,38 +255,38 @@ public abstract class PreferenceActivity extends ListActivity implements * Title of the header that is shown to the user. * @attr ref android.R.styleable#PreferenceHeader_title */ - CharSequence title; + public CharSequence title; /** * Optional summary describing what this header controls. * @attr ref android.R.styleable#PreferenceHeader_summary */ - CharSequence summary; + public CharSequence summary; /** * Optional icon resource to show for this header. * @attr ref android.R.styleable#PreferenceHeader_icon */ - int iconRes; + public int iconRes; /** * Optional icon drawable to show for this header. (If this is non-null, * the iconRes will be ignored.) */ - Drawable icon; + public Drawable icon; /** * Full class name of the fragment to display when this header is * selected. * @attr ref android.R.styleable#PreferenceHeader_fragment */ - String fragment; + public String fragment; /** * Optional arguments to supply to the fragment when it is * instantiated. */ - Bundle fragmentArguments; + public Bundle fragmentArguments; } @Override |