Emulyatorni sozlang, yangi loyiha yarating


Download 92.99 Kb.
Pdf ko'rish
bet14/14
Sana30.04.2023
Hajmi92.99 Kb.
#1417261
1   ...   6   7   8   9   10   11   12   13   14
Bog'liq
620-20 K.Temirov compressed

/ / nomi
private int
imageRes
;
/ / rasm
public
Image
(
String
name,
int
image){
this
.
name
=name;
this
.
imageRes
=image;
}
public


String
getName
() {
return this
.
name
;
}
public void
setName
(
String
name) {
this
.
name
= name;
}
public int
getImageResource
() {
return this
.
imageRes
;
}
public void
setImageResource
(
int
flagResource) {
this
.
imageRes
= flagResource;
}
}
Ikkinchi sinfni CustomRecyclerAdapter deb ataymiz, bu Sizning
RecyclerView uchun maxsus adapteringizni aniqlash va oxir
-oqibat kerakli ma'lumotlarni bog'lash va ro'yxatni ko'rsatish uchun kerak.
42
public class
CustomRecyclerAdapter
extends
RecyclerView
.
Adapter
<
CustomRecyclerAdapter
.
ViewHolder
>{
private final
LayoutInflater
inflater
;


private final
List
<
Image
>
images
;
CustomRecyclerAdapter
(
Context
context,
List
<
Image
> images) {
this
.
images
= images;
this
.
inflater
=
LayoutInflater
.from(context);
}
public void
onBindViewHolder
(
CustomRecyclerAdapter
.
ViewHolder
holder,
int
position) {
Image image
=
images
.get(position);
holder.
text
.setText(
image
.getName());
holder.
image
.setImageResource(
image
.getImageResource());
}
@NonNull
@Override
public
CustomRecyclerAdapter
.
ViewHolder
onCreateViewHolder
(
@NonNull
ViewGroup


parent,


int
viewType) {
View view
=
inflater
.inflate(
R
.
layout
.
list_item
, parent,
false
);
return new
ViewHolder(
view
);
}
@Override
public int
getItemCount
() {
return
images
.size();
}
public class
ViewHolder
extends
RecyclerView
.
ViewHolder
{
final
ImageView
image
;
final
TextView
text
;
ViewHolder
(
View
view){
super
(view);
image
= view.findViewById(
R
.
id
.
imageView
);

Download 92.99 Kb.

Do'stlaringiz bilan baham:
1   ...   6   7   8   9   10   11   12   13   14




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling