@Override public View getView(int position, View convertView, ViewGroup parent) { HeaderViewHolder holder; View view; if (convertView == null) { view = mInflater.inflate(R.layout.preference_header_item, parent, false); holder = new HeaderViewHolder(); holder.icon = (ImageView) view.findViewById(android.R.id.icon); holder.title = (TextView) view.findViewById(android.R.id.title); holder.summary = (TextView) view.findViewById(android.R.id.summary); view.setTag(holder); } else { view = convertView; holder = (HeaderViewHolder) view.getTag(); } // All view fields must be updated every time, because the view may be recycled Header header = getItem(position); holder.icon.setImageResource(header.iconRes); holder.title.setText(header.getTitle(getContext().getResources())); CharSequence summary = header.getSummary(getContext().getResources()); if (!TextUtils.isEmpty(summary)) { holder.summary.setVisibility(View.VISIBLE); holder.summary.setText(summary); } else { holder.summary.setVisibility(View.GONE); } return view; }
@Override public View getView(int position, View convertView, ViewGroup parent) { HeaderViewHolder holder; Header header = getItem(position); int headerType = getHeaderType(header); View view = null; if (convertView == null) { holder = new HeaderViewHolder(); switch (headerType) { case HEADER_TYPE_CATEGORY: view = new TextView(getContext(), null, android.R.attr.listSeparatorTextViewStyle); holder.title = (TextView) view; break; case HEADER_TYPE_NORMAL: view = mInflater.inflate(R.layout.preference_header_item, parent, false); holder.icon = (ImageView) view.findViewById(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); break; } view.setTag(holder); } else { view = convertView; holder = (HeaderViewHolder) view.getTag(); } // All view fields must be updated every time, because the view may be recycled switch (headerType) { case HEADER_TYPE_CATEGORY: holder.title.setText(header.getTitle(getContext().getResources())); break; case HEADER_TYPE_NORMAL: holder.icon.setImageResource(header.iconRes); holder.title.setText(header.getTitle(getContext().getResources())); CharSequence summary = header.getSummary(getContext().getResources()); if (!TextUtils.isEmpty(summary)) { holder.summary.setVisibility(View.VISIBLE); holder.summary.setText(summary); } else { holder.summary.setVisibility(View.GONE); } break; } return view; }
@Override public View getView(int position, View convertView, ViewGroup parent) { HeaderViewHolder holder; Header header = getItem(position); int headerType = getHeaderType(header); View view = null; if (convertView == null || headerType == HEADER_TYPE_SWITCH) { holder = new HeaderViewHolder(); switch (headerType) { case HEADER_TYPE_CATEGORY: view = new TextView(getContext(), null, android.R.attr.listSeparatorTextViewStyle); holder.title = (TextView) view; break; case HEADER_TYPE_SWITCH: view = mInflater.inflate(R.layout.preference_header_switch_item, parent, false); holder.icon = (ImageView) view.findViewById(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.switch_ = (Switch) view.findViewById(R.id.switchWidget); break; case HEADER_TYPE_NORMAL: view = mInflater.inflate(R.layout.preference_header_item, parent, false); holder.icon = (ImageView) view.findViewById(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); break; } view.setTag(holder); } else { view = convertView; holder = (HeaderViewHolder) view.getTag(); } // All view fields must be updated every time, because the view may be recycled switch (headerType) { case HEADER_TYPE_CATEGORY: holder.title.setText(header.getTitle(getContext().getResources())); break; case HEADER_TYPE_SWITCH: // Would need a different treatment if the main menu had more switches if (header.id == R.id.wifi_settings) { mWifiEnabler.setSwitch(holder.switch_); } else if (header.id == R.id.bluetooth_settings) { mBluetoothEnabler.setSwitch(holder.switch_); } else if (header.id == R.id.profiles_settings) { mProfileEnabler.setSwitch(holder.switch_); } else if (header.id == R.id.trds_settings) { mTRDSSwitch = (Switch) view.findViewById(R.id.switchWidget); mTRDSEnabler.setSwitch(holder.switch_); } // No break, fall through on purpose to update common fields // $FALL-THROUGH$ case HEADER_TYPE_NORMAL: if (header.extras != null && header.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) { String accType = header.extras.getString(ManageAccountsSettings.KEY_ACCOUNT_TYPE); ViewGroup.LayoutParams lp = holder.icon.getLayoutParams(); lp.width = getContext().getResources().getDimensionPixelSize(R.dimen.header_icon_width); lp.height = lp.width; holder.icon.setLayoutParams(lp); Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType); holder.icon.setImageDrawable(icon); } else { holder.icon.setImageResource(header.iconRes); } holder.title.setText(header.getTitle(getContext().getResources())); CharSequence summary = header.getSummary(getContext().getResources()); if (!TextUtils.isEmpty(summary)) { holder.summary.setVisibility(View.VISIBLE); holder.summary.setText(summary); } else { holder.summary.setVisibility(View.GONE); } break; } return view; }
@Override public View getView(int position, View convertView, ViewGroup parent) { HeaderViewHolder holder; Header header = getItem(position); int headerType = getHeaderType(header); View view; if (convertView == null) { holder = new HeaderViewHolder(); LinearLayout flview; flview = new LinearLayout(context); flview.setLayoutParams( new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Simple.DP(56))); if (headerType == HEADER_TYPE_NORMAL) { holder.icon = new ImageSmartView(context); Simple.setPadding(holder.icon, 24, 12, 0, 12); flview.addView( holder.icon, new LinearLayout.LayoutParams(Simple.DP(56), ViewGroup.LayoutParams.MATCH_PARENT)); } holder.title = new TextView(context); holder.title.setGravity(Gravity.CENTER_VERTICAL); Simple.setPadding(holder.title, 16, 0, 0, 0); flview.addView( holder.title, new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.START)); if (headerType == HEADER_TYPE_NORMAL) { Simple.setTextSize(holder.title, 17f); holder.title.setTextColor(0xff000000); } if (headerType == HEADER_TYPE_CATEGORY) { Simple.setTextSize(holder.title, 16f); Simple.setPadding(holder.title, 32, 0, 0, 0); flview.setBackgroundColor(0xcccccccc); } flview.setTag(holder); view = flview; } else { view = convertView; holder = (HeaderViewHolder) view.getTag(); } // // All view fields must be updated every time, // because the view may be recycled. // if (holder.icon != null) { if (header.iconRes != 0) { holder.icon.setImageResource(header.iconRes); } else { // // Check if we have a webapp here. // if (header.fragmentArguments != null) { String webappname = header.fragmentArguments.getString("webappname"); if (webappname != null) { if ((holder.icon.getTag() == null) || !Simple.equals((String) holder.icon.getTag(), webappname)) { holder.icon.setTag(webappname); holder.icon.setImageResource(webappname); } } } } } holder.title.setText(header.getTitle(getContext().getResources())); return view; }