@Test public void setContentView_shouldReplaceOldContentView() throws Exception { View view1 = new View(application); view1.setId(R.id.burritos); View view2 = new View(application); view2.setId(R.id.button); Activity activity = new Activity(); activity.setContentView(view1); assertSame(view1, activity.findViewById(R.id.burritos)); activity.setContentView(view2); assertNull(activity.findViewById(R.id.burritos)); assertSame(view2, activity.findViewById(R.id.button)); }
public void loadTable() { TableLayout table = (TableLayout) findViewById(R.id.table); // table.setColumnStretchable(1, true); table.removeAllViews(); final ArrayList<View> rowList = new ArrayList<View>(); for (int i = 0; i < balance.size(); i++) { // final LoaderImageView image = new LoaderImageView(getContext(), getUsersmallimg()); final LoaderImageView image = new LoaderImageView( getContext(), balance.get(i).getApp().getImageUrl(), (int) (ratio * 60), (int) (ratio * 60)); TableRow row = createRow( image, balance.get(i).getApp().getName(), balance.get(i).getCreationdate(), balance.get(i).getValue(), balance.get(i).getReason(), getContext()); row.setId(i); rowList.add(row); View spacer = createSpacer(getContext(), 1, 1); spacer.setId(-100); rowList.add(spacer); View spacer2 = createSpacer(getContext(), 2, 1); spacer2.setId(-100); rowList.add(spacer2); BeButton b = new BeButton(current.getContext()); if (i % 2 == 0) row.setBackgroundDrawable( b.setPressedBackg( new BDrawableGradient(0, (int) (ratio * 70), BDrawableGradient.LIGHT_GRAY_GRADIENT), new BDrawableGradient(0, (int) (ratio * 70), BDrawableGradient.HIGH_GRAY_GRADIENT), new BDrawableGradient( 0, (int) (ratio * 70), BDrawableGradient.HIGH_GRAY_GRADIENT))); else row.setBackgroundDrawable( b.setPressedBackg( new BDrawableGradient(0, (int) (ratio * 70), BDrawableGradient.GRAY_GRADIENT), new BDrawableGradient(0, (int) (ratio * 70), BDrawableGradient.HIGH_GRAY_GRADIENT), new BDrawableGradient( 0, (int) (ratio * 70), BDrawableGradient.HIGH_GRAY_GRADIENT))); } for (View row : rowList) { table.addView(row); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mainView = inflater.inflate(R.layout.fragment_logs, container, false); progressContainer = mainView.findViewById(R.id.progressContainer); // progressContainer.setId(INTERNAL_PROGRESS_CONTAINER_ID); listContainer = mainView.findViewById(R.id.listContainer); listContainer.setId(INTERNAL_LIST_CONTAINER_ID); internalEmpty = mainView.findViewById(R.id.internalEmpty); internalEmpty.setId(INTERNAL_EMPTY_ID); return mainView; }
/** * set id * * @param view */ public static void setId(View view) { if (view != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { try { // samsung SM-N9009(4.3) crash here, so protected view.setId(View.generateViewId()); } catch (Exception e) { view.setId(generateViewId()); } } else { view.setId(generateViewId()); } } }
@SuppressLint("InflateParams") @Override protected void initBody() { View view = mRoot.findViewById(R.id.jiaofei_company); initText(view, R.id.name, R.string.payment_common_jiaofei_company); initText(view, R.id.value, ((PaymentCommonSubmitBean) mParam).companyname); view = mRoot.findViewById(R.id.jiaofei_money); initText(view, R.id.name, R.string.payment_common_yingjiao_money); initText(view, R.id.value, ((PaymentCommonSubmitBean) mParam).needfare + "元"); ViewGroup zhifu = (ViewGroup) mRoot.findViewById(R.id.zhifu_channel); String[] channels = getResources().getStringArray(R.array.zhifu_channel); int size = channels.length; View group; for (int i = 0; i < size; i++) { group = LayoutInflater.from(this).inflate(R.layout.payment_common_zhifu_type, null); initTextImage(group, R.id.select_type_value, imageIds[i], channels[i]); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT); params.topMargin = 3; group.setId(i); initView(group); zhifu.addView(group, params); } }
public void setupNoSongsView() { View view = findViewById(ID_MUSIC_NO_SONGS_CONTENT); if (MusicUtils.mHasSongs == false) { if (view != null) { view.setVisibility(View.VISIBLE); } else { view = getLayoutInflater() .inflate( R.layout.music_no_songs, (ListView) findViewById(R.id.select_folder_list), false); view.setId(ID_MUSIC_NO_SONGS_CONTENT); // view.setPadding(0, mNoSongsPaddingTop, 0, 0); addContentView( view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); } TextView txtView = (TextView) view.findViewById(R.id.text_no_songs); String status = Environment.getExternalStorageState(); if (!(status.equals(Environment.MEDIA_MOUNTED))) { txtView.setText(R.string.nosd); } else { txtView.setText(R.string.no_folders); } } else { if (view != null) view.setVisibility(View.GONE); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { View view = convertView; if (convertView == null) { view = _inflater.inflate(R.layout.row_swipe, null); } Utils.setFontAllView(parent); VideoItem vidItem = _list.get(position); Integer id = vidItem.get_id(); View layer1 = view.findViewById(R.id.view_layer1); View layer2 = view.findViewById(R.id.view_layer2); TextView tvTitle = (TextView) view.findViewById(R.id.text_name); TextView tvDesc = (TextView) view.findViewById(R.id.text_desc); ImageView iv = (ImageView) view.findViewById(R.id.image); view.setId(id); tvTitle.setText(vidItem.get_title()); tvDesc.setText(vidItem.get_desc()); Bitmap bmp = Utils.GetImageFromAssets(this._context, "images/" + vidItem.get_image()); iv.setImageBitmap(bmp); detailViewListener(position, view); layer1.setVisibility(View.VISIBLE); layer2.setVisibility(View.INVISIBLE); return view; }
@SuppressWarnings("unchecked") @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { prefs = PreferenceManager.getDefaultSharedPreferences(super.getActivity()); View vv = super.getLayoutInflater(savedInstanceState).inflate(R.layout.widget_quiz, null); this.container = container; course = (Course) getArguments().getSerializable(Course.TAG); activity = ((Activity) getArguments().getSerializable(Activity.TAG)); this.setIsBaseline(getArguments().getBoolean(CourseActivity.BASELINE_TAG)); quizContent = ((Activity) getArguments().getSerializable(Activity.TAG)) .getContents( prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage())); LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); vv.setLayoutParams(lp); vv.setId(activity.getActId()); if ((savedInstanceState != null) && (savedInstanceState.getSerializable("widget_config") != null)) { setWidgetConfig( (HashMap<String, Object>) savedInstanceState.getSerializable("widget_config")); } return vv; }
private void addSaveButton(ViewGroup parentView, Activity activity) { View view = activity.getLayoutInflater().inflate(R.layout.form_field_save_button, parentView, true); int viewId = View.generateViewId(); view.setId(viewId); view.setOnClickListener((View.OnClickListener) activity); }
private void addNewItems() { currentChildCount = getChildCount(); parentLayout = false; int start = itemIds.size(); int end = Math.min(start + screenMaxColumns * rows * 2, adapter.getCount()); for (int i = start; i < end; i++) { int left = (i / rows) * (itemWidth + spaceHori); int top = (i % rows) * (spaceVert + itemHeight); RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(itemWidth, itemHeight); rlp.setMargins(left, top, 0, 0); View child = adapter.getView(i, null, this); this.addView(child, rlp); int viewId = child.getId(); if (viewId == -1) { viewId = TvUtil.buildId(); // 此处硬设置id同时建议开发者不用此范围id } child.setId(viewId); itemIds.put(viewId, i); bindEventOnChild(child, i); layoutFlag = true; } colCount = itemIds.size() % rows == 0 ? itemIds.size() / rows : itemIds.size() / rows + 1; }
public void registerContainer(String[] entityColumns, int[] rowFields) { if (entityColumns.length != rowFields.length) throw new RuntimeException( "Cannot assign " + entityColumns.length + " columns to " + rowFields.length + " fields on the row"); if (buttonIds.length != buttonListeners.length) throw new RuntimeException( "Cannot assign " + buttonListeners.length + " actions to " + buttonIds.length + " buttons"); ViewGroup container = (ViewGroup) activity.findViewById(layoutId); for (Entity e : list) { View newRow = activity.getLayoutInflater().inflate(rowLayoutId, container, false); newRow.setId((int) e.getId()); populateFields(entityColumns, rowFields, newRow, e); addButtonHandlers(newRow); container.addView(newRow); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View view = new FrameLayout(this); view.setId(CONTAINER_VIEW_ID); setContentView(view); }
public final View inflate() { ViewParent viewParent = getParent(); if (viewParent == null || !(viewParent instanceof ViewGroup)) { throw new IllegalStateException("ViewStub must have a non-null ViewGroup viewParent"); } else if (this.mLayoutResource != 0) { LayoutInflater factory; ViewGroup parent = (ViewGroup) viewParent; if (this.mInflater != null) { factory = this.mInflater; } else { factory = LayoutInflater.from(getContext()); } View view = factory.inflate(this.mLayoutResource, parent, false); if (this.mInflatedId != -1) { view.setId(this.mInflatedId); } int index = parent.indexOfChild(this); parent.removeViewInLayout(this); LayoutParams layoutParams = getLayoutParams(); if (layoutParams != null) { parent.addView(view, index, layoutParams); } else { parent.addView(view, index); } this.mInflatedViewRef = new WeakReference(view); if (this.mInflateListener != null) { this.mInflateListener.onInflate(this, view); } return view; } else { throw new IllegalArgumentException("ViewStub must have a valid layoutResource"); } }
public MenuItem setActionView(View view) { mActionView = view; mActionProvider = null; if (view != null && view.getId() == View.NO_ID && mId > 0) { view.setId(mId); } mMenu.onItemActionRequestChanged(this); return this; }
private void attachAdapter() { if (getHeight() == 0) { // try again! setAdapter(mAdapter); return; } final int itemCount = mAdapter.getCount(); int itemGroup = mAdapter.getItemsCountPerGroup(); if (itemGroup < 3) { itemGroup = 3; } final float height = getHeight(); final int itemHeight = (int) (height / itemGroup); int additionHeight = (int) (height - itemHeight * itemGroup); int itemPosition = 0; final int totalItems = itemCount + 2; for (int i = 0; i < totalItems; i++) { if (i == 0 || i == totalItems - 1) { TextView tv = (i == 0 ? mStartBlankView : mEndBlankView); mItemLayoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; mItemLayoutParams.height = (--additionHeight >= 0) ? itemHeight + 1 : itemHeight; tv.setLayoutParams(mItemLayoutParams); mItemsContainer.addView(tv); } else { View convertView = null; boolean isCached = true; if (itemPosition < mCachedSubViewList.size()) { convertView = mCachedSubViewList.get(itemPosition); } else { isCached = false; } View view = mAdapter.getView(itemPosition, convertView, this); view.setId(mAdapter.getItemId(itemPosition)); mItemLayoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; mItemLayoutParams.height = (--additionHeight >= 0) ? itemHeight + 1 : itemHeight; view.setLayoutParams(mItemLayoutParams); mItemsContainer.addView(view); if (!isCached) { mCachedSubViewList.add(itemPosition, view); } else { if (view != convertView) { mCachedSubViewList.remove(itemPosition); mCachedSubViewList.add(itemPosition, view); } } itemPosition++; } } }
private View createStatusBarView(Activity activity, int color) { // 绘制一个和状态栏一样高的矩形 View statusBarView = new View(activity); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, getStatusBarHeight(activity)); statusBarView.setLayoutParams(params); statusBarView.setBackgroundColor(color); statusBarView.setId(Integer.valueOf(1)); return statusBarView; }
protected View statusIcon() { LayoutParams params = new LayoutParams(stateIconSize, stateIconSize); params.addRule(ALIGN_PARENT_TOP); params.addRule(CENTER_VERTICAL); View v = new View(getContext()); v.setId(RandomId.get()); v.setLayoutParams(params); v.setBackgroundColor(Color.YELLOW); return v; }
protected void setNativeView(View view) { if (view.getId() == View.NO_ID) { view.setId(idGenerator.incrementAndGet()); } this.nativeView = view; boolean clickable = true; if (proxy.hasProperty(TiC.PROPERTY_TOUCH_ENABLED)) { clickable = TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_TOUCH_ENABLED)); } doSetClickable(nativeView, clickable); nativeView.setOnFocusChangeListener(this); }
private void initItems() { // 避免冲突 if (getChildCount() > 0) { return; } int screenWidth = wm.getDefaultDisplay().getWidth(); int initCols = screenWidth % rowWidth == 0 ? screenWidth / rowWidth : screenWidth / rowWidth + 1; int initLength = Math.min(adapter.getCount(), initCols * 2 * rows); for (int i = 0; i < initLength; i++) { int left = (i / rows) * (itemWidth + spaceHori); int top = (i % rows) * (spaceVert + itemHeight); RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(itemWidth, itemHeight); if (initLength == 1) { rlp.setMargins(left, top, 0, paddingTop * 2); } else { rlp.setMargins(left, top, 0, 0); } View child = adapter.getView(i, null, this); this.addView(child, rlp); int viewId = child.getId(); if (viewId == -1) { viewId = TvUtil.buildId(); // 此处硬设置id同时建议开发者不用此范围id } child.setId(viewId); itemIds.put(viewId, i); bindEventOnChild(child, i); layoutFlag = true; } colCount = itemIds.size() % rows == 0 ? itemIds.size() / rows : itemIds.size() / rows + 1; cursor = new ImageView(getContext()); cursorId = TvUtil.buildId(); cursor.setId(cursorId); cursor.setBackgroundResource(cursorRes); this.addView(cursor); cursor.setVisibility(View.INVISIBLE); if (initFocus) { View focus = ((ViewGroup) getParent()).findFocus(); if (focus == null) { View item = getChildAt(0); if (item != null) { item.requestFocus(); } } } }
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); final LinearLayout testBed = new LinearLayout(this); testBed.setOrientation(LinearLayout.VERTICAL); testBed.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); final int cacheSize = ViewConfiguration.getMaximumDrawingCacheSize(); final Display display = getWindowManager().getDefaultDisplay(); final int screenWidth = display.getWidth(); final int screenHeight = display.getHeight(); final View tiny = new View(this); tiny.setId(R.id.a); tiny.setBackgroundColor(0xFFFF0000); tiny.setLayoutParams(new LinearLayout.LayoutParams(screenWidth, screenHeight)); final View large = new View(this); large.setId(R.id.b); large.setBackgroundColor(0xFF00FF00); // Compute the height of the view assuming a cache size based on ARGB8888 final int height = 2 * (cacheSize / 2) / screenWidth; large.setLayoutParams(new LinearLayout.LayoutParams(screenWidth, height)); final ScrollView scroller = new ScrollView(this); scroller.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); testBed.addView(tiny); testBed.addView(large); scroller.addView(testBed); setContentView(scroller); }
public ItemViewHolder(View itemView) { super(itemView); itemView.setId(itemID); avatar = (SimpleDraweeView) itemView.findViewById(R.id.aty_topic_item_avatar); userName = (TextView) itemView.findViewById(R.id.aty_topic_item_name); university = (TextView) itemView.findViewById(R.id.aty_topic_item_university); time = (TextView) itemView.findViewById(R.id.aty_topic_item_time); title = (TextView) itemView.findViewById(R.id.aty_topic_item_title); content = (TextView) itemView.findViewById(R.id.aty_topic_item_content); like_number = (TextView) itemView.findViewById(R.id.aty_topic_item_like_number); comment_number = (TextView) itemView.findViewById(R.id.aty_topic_item_comment_number); grid = (GridLayout) itemView.findViewById(R.id.aty_topic_item_grid); grid.setNumInRow(4); }
@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (position == 2) { if (convertView == null) { convertView = inflater.inflate(R.layout.drawer_separator, null); } } else { if (convertView == null || convertView.getId() != position) { convertView = inflater.inflate(R.layout.drawer_row, null); if (convertView != null) { TextView textView = (TextView) convertView; convertView.setId(position); textView.setText(stringArray[position]); textView.setCompoundDrawablesWithIntrinsicBounds( drawableArray[position], null, null, null); } } if (convertView != null) { TextView textView = (TextView) convertView; Typeface roboto = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Medium.ttf"); textView.setTypeface(roboto); if (position == selectedItem) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = getContext().getTheme(); theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); int primaryDark = typedValue.data; ((ListView) parent).setSelectionFromTop(position, convertView.getTop()); textView.setTextColor(primaryDark); textView.getCompoundDrawables()[0].setColorFilter(primaryDark, PorterDuff.Mode.SRC_IN); TypedValue backgroundValue = new TypedValue(); getContext() .getTheme() .resolveAttribute(android.R.attr.galleryItemBackground, backgroundValue, true); convertView.setBackgroundColor(backgroundValue.data); } else { TypedValue colorValue = new TypedValue(); getContext() .getTheme() .resolveAttribute(android.R.attr.textColorPrimary, colorValue, true); textView.setTextColor(colorValue.data); convertView.setBackgroundColor(Color.TRANSPARENT); textView.getCompoundDrawables()[0].clearColorFilter(); } } else return null; } return convertView; }
private void init() { setLayoutParams( new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); mGestureListener = new SimpleOnGestureListener() { @Override public boolean onDown(MotionEvent e) { isFling = false; return true; } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // TODO if ((e1.getX() - e2.getX()) > MIN_FLING && velocityX < MAX_VELOCITYX) { isFling = true; } // Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX); return super.onFling(e1, e2, velocityX, velocityY); } }; mGestureDetector = new GestureDetectorCompat(getContext(), mGestureListener); // mScroller = ScrollerCompat.create(getContext(), new // BounceInterpolator()); if (mCloseInterpolator != null) { mCloseScroller = ScrollerCompat.create(getContext(), mCloseInterpolator); } else { mCloseScroller = ScrollerCompat.create(getContext()); } if (mOpenInterpolator != null) { mOpenScroller = ScrollerCompat.create(getContext(), mOpenInterpolator); } else { mOpenScroller = ScrollerCompat.create(getContext()); } LayoutParams contentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); mContentView.setLayoutParams(contentParams); if (mContentView.getId() < 1) { mContentView.setId(CONTENT_VIEW_ID); } mMenuView.setId(MENU_VIEW_ID); mMenuView.setLayoutParams( new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); addView(mContentView); addView(mMenuView); }
public static View a(View paramView, int paramInt1, int paramInt2) { View localView = paramView.findViewById(paramInt1); if (localView == null) { paramView = (ViewStub) paramView.findViewById(paramInt2); if (paramView != null) { paramView = paramView.inflate(); if (paramView.getId() != paramInt1) { paramView.setId(paramInt1); } return paramView; } } return localView; }
public DockedListView(Context context, AttributeSet attrs) { super(context, attrs); c = context; listView = new ListView(c); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); this.addView(listView, lp); dockedTempView = LayoutInflater.from(c).inflate(R.layout.docked_layout, null); dockedTempView.setId(DOCKED_TEMPVIEW_ID); lp = new RelativeLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); this.addView(dockedTempView, lp); dockedView = LayoutInflater.from(c).inflate(R.layout.docked_layout, null); dockedView.setId(DOCKED_VIEW_ID); headView = LayoutInflater.from(c).inflate(R.layout.listview_head_layout, null); ((ViewGroup) headView).addView(dockedView); listView.addHeaderView(headView); }
@Override public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = layoutInflater.inflate(R.layout.item_face, parent, false); } convertView.setId(position); // Show the face thumbnail. ((ImageView) convertView.findViewById(R.id.image_face)) .setImageBitmap(mFaceListAdapter.faceIdThumbnailMap.get(faces.get(position))); return convertView; }
private View getTableHorizontalLine(View leftBelowView, View rightBelowView) { LayoutParams params = new LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, (int) designSpec.getHorizontal().getHorizontalOneHeight()); params.addRule(ALIGN_LEFT, leftBelowView.getId()); params.addRule(ALIGN_RIGHT, rightBelowView.getId()); params.addRule(ALIGN_TOP, leftBelowView.getId()); View v = new View(getContext()); v.setId(RandomId.get()); v.setLayoutParams(params); v.setBackgroundColor(designSpec.getPrimaryColors().getHorizontalOne()); return v; }
private View getTableVerticalLine(View topRightOfView, View bottomRightOfView) { LayoutParams params = new LayoutParams( (int) designSpec.getHorizontal().getHorizontalOneHeight(), ViewGroup.LayoutParams.WRAP_CONTENT); params.addRule(ALIGN_TOP, topRightOfView.getId()); params.addRule(ALIGN_BOTTOM, bottomRightOfView.getId()); params.addRule(ALIGN_RIGHT, topRightOfView.getId()); View v = new View(getContext()); v.setId(RandomId.get()); v.setLayoutParams(params); v.setBackgroundColor(designSpec.getPrimaryColors().getHorizontalOne()); return v; }
@Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub ViewHolder holder = null; if (convertView == null) { convertView = mInflater.inflate(R.layout.ruyihelper_listview_icon_item, null); holder = new ViewHolder(); holder.title = (TextView) convertView.findViewById(R.id.ruyihelper_icon_text); holder.icon = (ImageView) convertView.findViewById(R.id.ruyihelper_iicon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } holder.title.setText(list.get(position).get("title").toString()); convertView.setId(Integer.parseInt(list.get(position).get("id").toString())); holder.icon.setBackgroundResource(R.drawable.xiangyou); return convertView; }
public View getView(int position, View convertView, ViewGroup parent) { final int itemViewType = getItemViewType(position); switch (itemViewType) { case ITEM_VIEW_TYPE_FOOTER: if (convertView == null || (int) convertView.getId() != ITEM_VIEW_TYPE_FOOTER) { convertView = LayoutInflater.from(getContext()) .inflate(R.layout.abs__activity_chooser_view_list_item, parent, false); convertView.setId(ITEM_VIEW_TYPE_FOOTER); TextView titleView = (TextView) convertView.findViewById(R.id.abs__title); titleView.setText(mContext.getString(R.string.abs__activity_chooser_view_see_all)); } return convertView; case ITEM_VIEW_TYPE_ACTIVITY: if (convertView == null || convertView.getId() != R.id.abs__list_item) { convertView = LayoutInflater.from(getContext()) .inflate(R.layout.abs__activity_chooser_view_list_item, parent, false); } PackageManager packageManager = mContext.getPackageManager(); // Set the icon ImageView iconView = (ImageView) convertView.findViewById(R.id.abs__icon); ResolveInfo activity = (ResolveInfo) getItem(position); iconView.setImageDrawable(activity.loadIcon(packageManager)); // Set the title. TextView titleView = (TextView) convertView.findViewById(R.id.abs__title); titleView.setText(activity.loadLabel(packageManager)); if (IS_HONEYCOMB) { // Highlight the default. if (mShowDefaultActivity && position == 0 && mHighlightDefaultActivity) { SetActivated.invoke(convertView, true); } else { SetActivated.invoke(convertView, false); } } return convertView; default: throw new IllegalArgumentException(); } }