1-dars. Android ilovalari haqida ikkita asosiy tushuncha


ListView-da bo'lgani kabi, RecyclerView



Download 1,09 Mb.
bet26/30
Sana02.02.2022
Hajmi1,09 Mb.
#426169
1   ...   22   23   24   25   26   27   28   29   30
Bog'liq
Android Studio ma`ruzalar

ListView-da bo'lgani kabi, RecyclerView-da ob'ektlarni ko'rsatish uchun biz adapterimizni aniqlab olishimiz kerak. Shuning uchun yangi ProgrammingLanguageAdapter sinfini ilovamizga qo'shamiz. Qo'shib bo'lgandan keyin, uni quyidagicha o'zgartiramiz:
package com.example.android.recyclerview;

import android.content.Context;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;


import java.util.List;


public class ProgrammingLanguageAdapter extends RecyclerView.Adapter


{

private LayoutInflater inflater;


private List
programmingLanguages;

ProgrammingLanguageAdapter(Context context, List


programmingLanguages) {
this.programmingLanguages = programmingLanguages;
this.inflater = LayoutInflater.from(context);
}

@Override


public ProgrammingLanguageAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = inflater.inflate(R.layout.list_item, parent, false);


return new ViewHolder(view);
}

@Override


public void onBindViewHolder(ProgrammingLanguageAdapter.ViewHolder holder, int position) {
ProgrammingLanguage programmingLanguage = programmingLanguages.get(position);
holder.imageView.setImageResource(programmingLanguage.getImage());
holder.nameView.setText(programmingLanguage.getName());
}

@Override


public int getItemCount() {
return programmingLanguages.size();
}

public static class ViewHolder extends RecyclerView.ViewHolder {


final ImageView imageView;
final TextView nameView;

ViewHolder(View view) {


super(view);
imageView = view.findViewById(R.id.image);
nameView = view.findViewById(R.id.name);
}
}
}

Download 1,09 Mb.

Do'stlaringiz bilan baham:
1   ...   22   23   24   25   26   27   28   29   30




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish