OnCreateViewHolder yog dab tsi?
OnCreateViewHolder yog dab tsi?

Video: OnCreateViewHolder yog dab tsi?

Video: OnCreateViewHolder yog dab tsi?
Video: View Binding in RecyclerView with Custom Adapter in Android Studio 3.6+ | AndroidX | 2020 2024, Hlis ntuj nqeg
Anonim

onCreateViewHolder (ViewGroup, ib.)

Txoj kev no yog hu ua txoj cai thaum lub adapter tsim thiab siv los pib koj lub ViewHolder(s).

Tom qab ntawd, ViewType yog dab tsi hauv onCreateViewHolder?

Yog li pib, onCreateViewHolder (ViewGroup niam txiv, int saibType ) tsuas yog hu thaum xav tau kev pom tshiab; getItemViewType(int position) yuav raug hu rau saibType ; Yog li thaum onBindViewHolder hu ua nws yuav tsum tau muab tso rau hauv txoj cai saib layout thiab hloov tshiab ViewHolder.

Tsis tas li ntawd, kev siv onBindViewHolder hauv Android yog dab tsi? ntawmBindViewHolder . Hu los ntawm RecyclerView los tso saib cov ntaub ntawv ntawm qhov chaw teev tseg. Txoj kev no yuav tsum hloov kho cov ntsiab lus ntawm itemView kom muaj kev cuam tshuam cov khoom ntawm qhov chaw muab.

Sib piv, ViewHolder yog dab tsi hauv RecyclerView?

RecyclerView . ViewHolder yog ib chav pab uas tuav lub View ntawm ib kab lossis kab. Ib lossis ntau dua ViewHolder yog tsim rau txhua viewType. yog tias ob peb kab muaj tib ViewType ces tib View tuaj yeem rov qab siv tau rau ob peb kab. Adapter onBindViewHolder yog qhov chaw sau qhov pom nrog cov ntaub ntawv tshwj xeeb rau txhua kab.

RecyclerView adapter yog dab tsi?

Hauv Android 5.0 hli, Android qhia RecyclerView widget. RecyclerView yog hloov tau thiab ua tau zoo version ntawm ListView. Nws yog ib lub thawv rau rendering loj cov ntaub ntawv teev cov views uas yuav tsum tau recycled thiab scrolled heev npaum. Adapter rau muab views uas sawv cev rau cov khoom nyob rau hauv ib cov ntaub ntawv teev.

Pom zoo: