1、ListView使用ViewHolder极简写法
/** * 在指定View中依据指定ID寻找控件(内置ViewHolder缓存) * * @param convertView * 容器 * @param id * 控件ID * @return 找到的控件 */ @SuppressWarnings("unchecked") public static使用方法:T getAdapterView(View convertView, int id) { SparseArray viewHolder = (SparseArray ) convertView.getTag(); if (viewHolder == null) { viewHolder = new SparseArray (); convertView.setTag(viewHolder); } View childView = viewHolder.get(id); if (childView == null) { childView = convertView.findViewById(id); viewHolder.put(id, childView); } return (T) childView; }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_feed_item, parent, false); } ImageView thumnailView = getAdapterView(convertView, R.id.video_thumbnail); ImageView avatarView = getAdapterView(convertView, R.id.user_avatar); ImageView appIconView = getAdapterView(convertView, R.id.app_icon);2、 设置Activity透明
说明:AppBaseTheme通常是你application指定的android:theme是啥这里就是啥。否则Activity内部的空间风格可能不一致。
用途:用于模拟Dialog效果。比方再Service中没法用Dialog,就能够用Activity来模拟
3、/** * 获取设备上全部已安装并能够启动的应用的包名集合 * * @param context * 上下文对象 * @return 满足条件的包名的集合 */ public static List使用getInstalledPackages会返回非常多无法启动甚至没有图标的系统应用。getAllCanOpenApp(Context context) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); List activities = context.getPackageManager() .queryIntentActivities(intent, 0); if (DataUtil.isEmpty(activities)) { return null; } List list = new ArrayList (); String packName; for (ResolveInfo info : activities) { packName=info.activityInfo.packageName; if(DataUtil.isEmpty(packName)){ continue; } list.add(packName); } return list; }