private final HashSet nestViews;
private final LinkedHashSet childClickViewIds;
private final LinkedHashSet itemChildLongClickViewIds;
private BaseDelegateAdapter adapter;
/**
- use itemView instead
*/
@Deprecated
public View convertView;
/**
- Package private field to retain the associated user object and detect a change
*/
Object associatedObject;
public BaseDelegateViewHolder(final View view) {
super(view);
this.views = new SparseArray<>();
this.childClickViewIds = new LinkedHashSet<>();
this.itemChildLongClickViewIds = new LinkedHashSet<>();
this.nestViews = new HashSet<>();
convertView = view;
}
private int getClickPosition() {
return getLayoutPosition();
}
public HashSet getItemChildLongClickViewIds() {
return itemChildLongClickViewIds;
}
public HashSet getChildClickViewIds() {
return childClickViewIds;
}
/**
-
use itemView instead
-
@return the ViewHolder root view
*/
@Deprecated
public View getConvertView() {
return convertView;
}
/**
-
Will set the text of a TextView.
-
@param viewId The view id.
-
@param value The text to put in the text view.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setText(@IdRes int viewId, CharSequence value) {
TextView view = getView(viewId);
view.setText(value);
return this;
}
public BaseDelegateViewHolder setText(@IdRes int viewId, @StringRes int strId) {
TextView view = getView(viewId);
view.setText(strId);
return this;
}
/**
-
Will set the image of an ImageView from a resource id.
-
@param viewId The view id.
-
@param imageResId The image resource id.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setImageResource(@IdRes int viewId, @DrawableRes int imageResId) {
ImageView view = getView(viewId);
view.setImageResource(imageResId);
return this;
}
/**
-
Will set background color of a view.
-
@param viewId The view id.
-
@param color A color, not a resource id.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setBackgroundColor(@IdRes int viewId, @ColorInt int color) {
View view = getView(viewId);
view.setBackgroundColor(color);
return this;
}
/**
-
Will set background of a view.
-
@param viewId The view id.
-
@param backgroundRes A resource to use as a background.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setBackgroundRes(@IdRes int viewId, @DrawableRes int backgroundRes) {
View view = getView(viewId);
view.setBackgroundResource(backgroundRes);
return this;
}
/**
-
Will set text color of a TextView.
-
@param viewId The view id.
-
@param textColor The text color (not a resource id).
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setTextColor(@IdRes int viewId, @ColorInt int textColor) {
TextView view = getView(viewId);
view.setTextColor(textColor);
return this;
}
/**
-
Will set the image of an ImageView from a drawable.
-
@param viewId The view id.
-
@param drawable The image drawable.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setImageDrawable(@IdRes int viewId, Drawable drawable) {
ImageView view = getView(viewId);
view.setImageDrawable(drawable);
return this;
}
/**
- Add an action to set the image of an image view. Can be called multiple times.
*/
public BaseDelegateViewHolder setImageBitmap(@IdRes int viewId, Bitmap bitmap) {
ImageView view = getView(viewId);
view.setImageBitmap(bitmap);
return this;
}
/**
-
Add an action to set the alpha of a view. Can be called multiple times.
-
Alpha between 0-1.
*/
public BaseDelegateViewHolder setAlpha(@IdRes int viewId, float value) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getView(viewId).setAlpha(value);
} else {
// Pre-honeycomb hack to set Alpha value
AlphaAnimation alpha = new AlphaAnimation(value, value);
alpha.setDuration(0);
alpha.setFillAfter(true);
getView(viewId).startAnimation(alpha);
}
return this;
}
/**
-
Set a view visibility to VISIBLE (true) or GONE (false).
-
@param viewId The view id.
-
@param visible True for VISIBLE, false for GONE.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setGone(@IdRes int viewId, boolean visible) {
View view = getView(viewId);
view.setVisibility(visible ? View.VISIBLE : View.GONE);
return this;
}
/**
-
Set a view visibility to VISIBLE (true) or INVISIBLE (false).
-
@param viewId The view id.
-
@param visible True for VISIBLE, false for INVISIBLE.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setVisible(@IdRes int viewId, boolean visible) {
View view = getView(viewId);
view.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
return this;
}
/**
-
Add links into a TextView.
-
@param viewId The id of the TextView to linkify.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder linkify(@IdRes int viewId) {
TextView view = getView(viewId);
Linkify.addLinks(view, Linkify.ALL);
return this;
}
/**
- Apply the typeface to the given viewId, and enable subpixel rendering.
*/
public BaseDelegateViewHolder setTypeface(@IdRes int viewId, Typeface typeface) {
TextView view = getView(viewId);
view.setTypeface(typeface);
view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
return this;
}
/**
- Apply the typeface to all the given viewIds, and enable subpixel rendering.
*/
public BaseDelegateViewHolder setTypeface(Typeface typeface, int… viewIds) {
for (int viewId : viewIds) {
TextView view = getView(viewId);
view.setTypeface(typeface);
view.setPaintFlags(view.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
}
return this;
}
/**
-
Sets the progress of a ProgressBar.
-
@param viewId The view id.
-
@param progress The progress.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setProgress(@IdRes int viewId, int progress) {
ProgressBar view = getView(viewId);
view.setProgress(progress);
return this;
}
/**
-
Sets the progress and max of a ProgressBar.
-
@param viewId The view id.
-
@param progress The progress.
-
@param max The max value of a ProgressBar.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setProgress(@IdRes int viewId, int progress, int max) {
ProgressBar view = getView(viewId);
view.setMax(max);
view.setProgress(progress);
return this;
}
/**
-
Sets the range of a ProgressBar to 0…max.
-
@param viewId The view id.
-
@param max The max value of a ProgressBar.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setMax(@IdRes int viewId, int max) {
ProgressBar view = getView(viewId);
view.setMax(max);
return this;
}
/**
-
Sets the rating (the number of stars filled) of a RatingBar.
-
@param viewId The view id.
-
@param rating The rating.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setRating(@IdRes int viewId, float rating) {
RatingBar view = getView(viewId);
view.setRating(rating);
return this;
}
/**
-
Sets the rating (the number of stars filled) and max of a RatingBar.
-
@param viewId The view id.
-
@param rating The rating.
-
@param max The range of the RatingBar to 0…max.
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setRating(@IdRes int viewId, float rating, int max) {
RatingBar view = getView(viewId);
view.setMax(max);
view.setRating(rating);
return this;
}
/**
-
Sets the tag of the view.
-
@param viewId The view id.
-
@param tag The tag;
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setTag(@IdRes int viewId, Object tag) {
View view = getView(viewId);
view.setTag(tag);
return this;
}
/**
-
Sets the tag of the view.
-
@param viewId The view id.
-
@param key The key of tag;
-
@param tag The tag;
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setTag(@IdRes int viewId, int key, Object tag) {
View view = getView(viewId);
view.setTag(key, tag);
return this;
}
/**
-
Sets the checked status of a checkable.
-
@param viewId The view id.
-
@param checked The checked status;
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setChecked(@IdRes int viewId, boolean checked) {
View view = getView(viewId);
// View unable cast to Checkable
if (view instanceof Checkable) {
((Checkable) view).setChecked(checked);
}
return this;
}
/**
-
Set the enabled state of this view.
-
@param viewId The view id.
-
@param enable The checked status;
-
@return The BaseViewHolder for chaining.
*/
public BaseDelegateViewHolder setEnabled(@IdRes int viewId,boolean enable) {
View view = getView(viewId);
view.setEnabled(enable);
return this;
}
@SuppressWarnings(“unchecked”)
public T getView(@IdRes int viewId) {
View view = views.get(viewId);
if (view == null) {
view = itemView.findViewById(viewId);
views.put(viewId, view);
}
return (T) view;
}
/**
- Retrieves the last converted object on this view.
*/
public Object getAssociatedObject() {
return associatedObject;
}
/**
- Should be called during convert
*/
public void setAssociatedObject(Object associatedObject) {
this.associatedObject = associatedObject;
}
}
2.Adapter(包含item的点击事件和长按事件)
public abstract class BaseDelegateAdapter<T, VH extends RecyclerView.ViewHolder> extends DelegateAdapter.Adapter{
private static final String TAG = BaseDelegateAdapter.class.getSimpleName();
public Context mContext;
private LayoutInflater mLayoutInflater;
private int mLayoutResId;
private List mData;
private LayoutHelper mLayoutHelper;
public BaseDelegateAdapter(@LayoutRes int layoutResId, @Nullable List data, LayoutHelper layoutHelper) {
this.mData = data == null ? new ArrayList<>() : data;
if (layoutResId != 0) {
this.mLayoutResId = layoutResId;
}
this.mLayoutHelper = layoutHelper;
}
/**
- 删除一条数据
*/
public void removeItem(int position) {
mData.remove(position);
// 暴力刷新
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
总结
首先是感觉自己的基础还是不够吧,大厂好像都喜欢问这些底层原理。
另外一部分原因在于资料也还没有看完,一面时凭借那份资料考前突击恶补个几天居然也能轻松应对(在这里还是要感谢那份资料,真的牛),于是自我感觉良好,资料就没有怎么深究下去了。
之前的准备只涉及了Java、Android、计网、数据结构与算法这些方面,面对面试官对其他基础课程的考察显得捉襟见肘。
下一步还是要查漏补缺,进行针对性复习。
最后的最后,那套资料这次一定要全部看完,是真的太全面了,各个知识点都涵盖了,几乎我面试遇到的所有问题的知识点这里面都有!希望大家不要犯和我一样的错误呀!!!一定要看完!
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
UpVD5Uv-1713598438039)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
总结
首先是感觉自己的基础还是不够吧,大厂好像都喜欢问这些底层原理。
另外一部分原因在于资料也还没有看完,一面时凭借那份资料考前突击恶补个几天居然也能轻松应对(在这里还是要感谢那份资料,真的牛),于是自我感觉良好,资料就没有怎么深究下去了。
之前的准备只涉及了Java、Android、计网、数据结构与算法这些方面,面对面试官对其他基础课程的考察显得捉襟见肘。
下一步还是要查漏补缺,进行针对性复习。
最后的最后,那套资料这次一定要全部看完,是真的太全面了,各个知识点都涵盖了,几乎我面试遇到的所有问题的知识点这里面都有!希望大家不要犯和我一样的错误呀!!!一定要看完!
[外链图片转存中…(img-5C7UXxmX-1713598438040)]
[外链图片转存中…(img-7EyhP0NU-1713598438041)]
[外链图片转存中…(img-4aend7Yq-1713598438042)]
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!