Java ViewHolder中类型视图的字段itemView引用了什么?

Java ViewHolder中类型视图的字段itemView引用了什么?,java,android,Java,Android,我正在试图找出字段itemView实际上是什么。下面是我从文档中提取的代码片段 public abstract static class ViewHolder { @NonNull public final View itemView; // others removed for simplicity } 如果我们扩展了ViewHolder类,因为我们还需要指定一些从View派生的类型字段来为每个列表项保存我们自己的小部件,那么很明显,itemVi

我正在试图找出字段
itemView
实际上是什么。下面是我从文档中提取的代码片段

public abstract static class ViewHolder {
        @NonNull
        public final View itemView;
       // others removed for simplicity
}
如果我们扩展了
ViewHolder
类,因为我们还需要指定一些从
View
派生的类型字段来为每个列表项保存我们自己的小部件,那么很明显,
itemView
将不会保存我们自己的小部件

问题:
itemView
字段引用什么?我不知道它是引用了
RecyclerView
还是引用了
list\u item\u layout.xml
(包含我们自己的小部件)的根视图。你能澄清一下是哪一个吗

编辑 欲了解
ViewHolder
的内部详细信息,请参阅以下内容。我提出完整的一个

public abstract static class ViewHolder {
        @NonNull
        public final View itemView;
        WeakReference<RecyclerView> mNestedRecyclerView;
        int mPosition = -1;
        int mOldPosition = -1;
        long mItemId = -1L;
        int mItemViewType = -1;
        int mPreLayoutPosition = -1;
        RecyclerView.ViewHolder mShadowedHolder = null;
        RecyclerView.ViewHolder mShadowingHolder = null;
        static final int FLAG_BOUND = 1;
        static final int FLAG_UPDATE = 2;
        static final int FLAG_INVALID = 4;
        static final int FLAG_REMOVED = 8;
        static final int FLAG_NOT_RECYCLABLE = 16;
        static final int FLAG_RETURNED_FROM_SCRAP = 32;
        static final int FLAG_IGNORE = 128;
        static final int FLAG_TMP_DETACHED = 256;
        static final int FLAG_ADAPTER_POSITION_UNKNOWN = 512;
        static final int FLAG_ADAPTER_FULLUPDATE = 1024;
        static final int FLAG_MOVED = 2048;
        static final int FLAG_APPEARED_IN_PRE_LAYOUT = 4096;
        static final int PENDING_ACCESSIBILITY_STATE_NOT_SET = -1;
        static final int FLAG_BOUNCED_FROM_HIDDEN_LIST = 8192;
        static final int FLAG_SET_A11Y_ITEM_DELEGATE = 16384;
        int mFlags;
        private static final List<Object> FULLUPDATE_PAYLOADS = Collections.emptyList();
        List<Object> mPayloads = null;
        List<Object> mUnmodifiedPayloads = null;
        private int mIsRecyclableCount = 0;
        RecyclerView.Recycler mScrapContainer = null;
        boolean mInChangeScrap = false;
        private int mWasImportantForAccessibilityBeforeHidden = 0;
        @VisibleForTesting
        int mPendingAccessibilityState = -1;
        RecyclerView mOwnerRecyclerView;

        public ViewHolder(@NonNull View itemView) {
            if (itemView == null) {
                throw new IllegalArgumentException("itemView may not be null");
            } else {
                this.itemView = itemView;
            }
        }

        void flagRemovedAndOffsetPosition(int mNewPosition, int offset, boolean applyToPreLayout) {
            this.addFlags(8);
            this.offsetPosition(offset, applyToPreLayout);
            this.mPosition = mNewPosition;
        }

        void offsetPosition(int offset, boolean applyToPreLayout) {
            if (this.mOldPosition == -1) {
                this.mOldPosition = this.mPosition;
            }

            if (this.mPreLayoutPosition == -1) {
                this.mPreLayoutPosition = this.mPosition;
            }

            if (applyToPreLayout) {
                this.mPreLayoutPosition += offset;
            }

            this.mPosition += offset;
            if (this.itemView.getLayoutParams() != null) {
                ((RecyclerView.LayoutParams)this.itemView.getLayoutParams()).mInsetsDirty = true;
            }

        }

        void clearOldPosition() {
            this.mOldPosition = -1;
            this.mPreLayoutPosition = -1;
        }

        void saveOldPosition() {
            if (this.mOldPosition == -1) {
                this.mOldPosition = this.mPosition;
            }

        }

        boolean shouldIgnore() {
            return (this.mFlags & 128) != 0;
        }

        /** @deprecated */
        @Deprecated
        public final int getPosition() {
            return this.mPreLayoutPosition == -1 ? this.mPosition : this.mPreLayoutPosition;
        }

        public final int getLayoutPosition() {
            return this.mPreLayoutPosition == -1 ? this.mPosition : this.mPreLayoutPosition;
        }

        public final int getAdapterPosition() {
            return this.mOwnerRecyclerView == null ? -1 : this.mOwnerRecyclerView.getAdapterPositionFor(this);
        }

        public final int getOldPosition() {
            return this.mOldPosition;
        }

        public final long getItemId() {
            return this.mItemId;
        }

        public final int getItemViewType() {
            return this.mItemViewType;
        }

        boolean isScrap() {
            return this.mScrapContainer != null;
        }

        void unScrap() {
            this.mScrapContainer.unscrapView(this);
        }

        boolean wasReturnedFromScrap() {
            return (this.mFlags & 32) != 0;
        }

        void clearReturnedFromScrapFlag() {
            this.mFlags &= -33;
        }

        void clearTmpDetachFlag() {
            this.mFlags &= -257;
        }

        void stopIgnoring() {
            this.mFlags &= -129;
        }

        void setScrapContainer(RecyclerView.Recycler recycler, boolean isChangeScrap) {
            this.mScrapContainer = recycler;
            this.mInChangeScrap = isChangeScrap;
        }

        boolean isInvalid() {
            return (this.mFlags & 4) != 0;
        }

        boolean needsUpdate() {
            return (this.mFlags & 2) != 0;
        }

        boolean isBound() {
            return (this.mFlags & 1) != 0;
        }

        boolean isRemoved() {
            return (this.mFlags & 8) != 0;
        }

        boolean hasAnyOfTheFlags(int flags) {
            return (this.mFlags & flags) != 0;
        }

        boolean isTmpDetached() {
            return (this.mFlags & 256) != 0;
        }

        boolean isAdapterPositionUnknown() {
            return (this.mFlags & 512) != 0 || this.isInvalid();
        }

        void setFlags(int flags, int mask) {
            this.mFlags = this.mFlags & ~mask | flags & mask;
        }

        void addFlags(int flags) {
            this.mFlags |= flags;
        }

        void addChangePayload(Object payload) {
            if (payload == null) {
                this.addFlags(1024);
            } else if ((this.mFlags & 1024) == 0) {
                this.createPayloadsIfNeeded();
                this.mPayloads.add(payload);
            }

        }

        private void createPayloadsIfNeeded() {
            if (this.mPayloads == null) {
                this.mPayloads = new ArrayList();
                this.mUnmodifiedPayloads = Collections.unmodifiableList(this.mPayloads);
            }

        }

        void clearPayload() {
            if (this.mPayloads != null) {
                this.mPayloads.clear();
            }

            this.mFlags &= -1025;
        }

        List<Object> getUnmodifiedPayloads() {
            if ((this.mFlags & 1024) == 0) {
                return this.mPayloads != null && this.mPayloads.size() != 0 ? this.mUnmodifiedPayloads : FULLUPDATE_PAYLOADS;
            } else {
                return FULLUPDATE_PAYLOADS;
            }
        }

        void resetInternal() {
            this.mFlags = 0;
            this.mPosition = -1;
            this.mOldPosition = -1;
            this.mItemId = -1L;
            this.mPreLayoutPosition = -1;
            this.mIsRecyclableCount = 0;
            this.mShadowedHolder = null;
            this.mShadowingHolder = null;
            this.clearPayload();
            this.mWasImportantForAccessibilityBeforeHidden = 0;
            this.mPendingAccessibilityState = -1;
            RecyclerView.clearNestedRecyclerViewIfNotNested(this);
        }

        void onEnteredHiddenState(RecyclerView parent) {
            if (this.mPendingAccessibilityState != -1) {
                this.mWasImportantForAccessibilityBeforeHidden = this.mPendingAccessibilityState;
            } else {
                this.mWasImportantForAccessibilityBeforeHidden = ViewCompat.getImportantForAccessibility(this.itemView);
            }

            parent.setChildImportantForAccessibilityInternal(this, 4);
        }

        void onLeftHiddenState(RecyclerView parent) {
            parent.setChildImportantForAccessibilityInternal(this, this.mWasImportantForAccessibilityBeforeHidden);
            this.mWasImportantForAccessibilityBeforeHidden = 0;
        }

        public String toString() {
            StringBuilder sb = new StringBuilder("ViewHolder{" + Integer.toHexString(this.hashCode()) + " position=" + this.mPosition + " id=" + this.mItemId + ", oldPos=" + this.mOldPosition + ", pLpos:" + this.mPreLayoutPosition);
            if (this.isScrap()) {
                sb.append(" scrap ").append(this.mInChangeScrap ? "[changeScrap]" : "[attachedScrap]");
            }

            if (this.isInvalid()) {
                sb.append(" invalid");
            }

            if (!this.isBound()) {
                sb.append(" unbound");
            }

            if (this.needsUpdate()) {
                sb.append(" update");
            }

            if (this.isRemoved()) {
                sb.append(" removed");
            }

            if (this.shouldIgnore()) {
                sb.append(" ignored");
            }

            if (this.isTmpDetached()) {
                sb.append(" tmpDetached");
            }

            if (!this.isRecyclable()) {
                sb.append(" not recyclable(" + this.mIsRecyclableCount + ")");
            }

            if (this.isAdapterPositionUnknown()) {
                sb.append(" undefined adapter position");
            }

            if (this.itemView.getParent() == null) {
                sb.append(" no parent");
            }

            sb.append("}");
            return sb.toString();
        }

        public final void setIsRecyclable(boolean recyclable) {
            this.mIsRecyclableCount = recyclable ? this.mIsRecyclableCount - 1 : this.mIsRecyclableCount + 1;
            if (this.mIsRecyclableCount < 0) {
                this.mIsRecyclableCount = 0;
                Log.e("View", "isRecyclable decremented below 0: unmatched pair of setIsRecyable() calls for " + this);
            } else if (!recyclable && this.mIsRecyclableCount == 1) {
                this.mFlags |= 16;
            } else if (recyclable && this.mIsRecyclableCount == 0) {
                this.mFlags &= -17;
            }

        }

        public final boolean isRecyclable() {
            return (this.mFlags & 16) == 0 && !ViewCompat.hasTransientState(this.itemView);
        }

        boolean shouldBeKeptAsChild() {
            return (this.mFlags & 16) != 0;
        }

        boolean doesTransientStatePreventRecycling() {
            return (this.mFlags & 16) == 0 && ViewCompat.hasTransientState(this.itemView);
        }

        boolean isUpdated() {
            return (this.mFlags & 2) != 0;
        }
    }
公共抽象静态类ViewHolder{
@非空
公共最终视图项目视图;
WeakReference mNestedRecyclerView;
int-mPosition=-1;
int mOldPosition=-1;
长斜接=1L;
int-mItemViewType=-1;
int-mPreLayoutPosition=-1;
RecyclerView.ViewHolder mShadowedHolder=null;
RecyclerView.ViewHolder mShadowingHolder=null;
静态最终整数标志_BOUND=1;
静态最终整数标志_UPDATE=2;
静态最终整数标志_无效=4;
静态最终整型标志_移除=8;
静态最终整数标志不可回收=16;
静态最终整数标志\u从\u废料返回\u=32;
静态最终整数标志_IGNORE=128;
静态最终int标志\u TMP\u分离=256;
静态最终整数标志\适配器\位置\未知=512;
静态最终int标志\u适配器\u FULLUPDATE=1024;
静态最终整数标志_MOVED=2048;
静态最终整型标志\u在\u PRE\u布局中出现\u=4096;
静态最终整型挂起\u可访问性\u状态\u非\u集=-1;
静态最终整数标志从隐藏列表中反弹=8192;
静态最终整型标志集项目委托=16384;
int-mFlags;
私有静态最终列表FULLUPDATE_PAYLOADS=Collections.emptyList();
列表mpailoads=null;
列表mundModifiedPayLoads=null;
私有整数可回收错误计数=0;
RecyclerView.Recycler mScrapContainer=null;
布尔值mInChangeScrap=false;
private int mWasImportantForAccessibilityBeforeHidden=0;
@可视性测试
int mPendingAccessibilityState=-1;
RecyclerView割草机RecyclerView;
公共视图持有者(@NonNull View itemView){
如果(itemView==null){
抛出新的IllegalArgumentException(“itemView可能不为null”);
}否则{
this.itemView=itemView;
}
}
void flagRemovedAndOffsetPosition(整数mNewPosition、整数偏移、布尔applyToPreLayout){
这是addFlags(8);
此偏移位置(偏移,应用预布局);
this.mPosition=mNewPosition;
}
void offsetPosition(整数偏移,布尔applyToPreLayout){
if(this.mOldPosition==-1){
this.mOldPosition=this.mPosition;
}
if(this.mPreLayoutPosition==-1){
this.mPreLayoutPosition=this.mPreLayoutPosition;
}
如果(应用预布局){
此.mPreLayoutPosition+=偏移量;
}
此.mPosition+=偏移量;
if(this.itemView.getLayoutParams()!=null){
((RecyclerView.LayoutParams)this.itemView.getLayoutParams()).mInsetsDirty=true;
}
}
void clearloldposition(){
this.mOldPosition=-1;
this.mPreLayoutPosition=-1;
}
void saveOldPosition(){
if(this.mOldPosition==-1){
this.mOldPosition=this.mPosition;
}
}
布尔shouldinore(){
返回(this.mFlags&128)!=0;
}
/**@弃用*/
@不赞成
公共最终int getPosition(){
返回this.mPreLayoutPosition==-1?this.mPreLayoutPosition:this.mPreLayoutPosition;
}
public final int getLayoutPosition(){
返回this.mPreLayoutPosition==-1?this.mPreLayoutPosition:this.mPreLayoutPosition;
}
公共最终整型getAdapterPosition(){
返回this.mOwnerRecyclerView==null?-1:this.mOwnerRecyclerView.getAdapterPositionFor(this);
}
公共最终整数getOldPosition(){
返回此.mOldPosition;
}
公共最终长getItemId(){
把这个还给我;
}
public final int getItemViewType(){
返回此.mItemViewType;
}
布尔isScrap(){
返回this.mScrapContainer!=null;
}
撤销联合国安理会决议(){
this.mScrapContainer.uncapview(this);
}
布尔值是从废料()返回的{
返回(this.mFlags&32)!=0;
}
作废clearReturnedFromScrapFlag(){
这个.mFlags&=-33;
}
void clearTmpDetachFlag(){
这个.mFlags&=-257;
}
void stop忽略(){
这个.mFlags&=-129;
}
void setScrapContainer(RecyclerView.Recycler Recycler,布尔值IsChangeScrape){
this.mScrapContainer=回收商;
this.mInChangeScrap=isChangeScrap;
}
布尔值isInvalid(){
返回(this.mFlags&4)!=0;
}
布尔值needsUpdate(){
返回值(this.mFlags&2)!=0;
}
布尔isBound(){
返回(this.mFlags&1)!=0;
}
布尔值isRemoved(){
返回(this.mFlags&8)!=0;
}
布尔hasanyoff标志(int标志){
返回(this.mFlags&flags)!=0;
}
布尔值(){
返回(this.mFlags&256)!
public MyAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent,
                                               int viewType) {
    // create a new view
    TextView v = (TextView) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.my_text_view, parent, false);
    ...
    MyViewHolder vh = new MyViewHolder(v);
    return vh;
}