Guruh talabasi Abdiyev Husniddin Adapter bo‘yicha qo‘llanma Android Studioda misol


BaseAdapter-ni kengaytiradigan maxsus adapter kodi


Download 1.52 Mb.
bet2/6
Sana24.12.2022
Hajmi1.52 Mb.
#1059102
1   2   3   4   5   6
Bog'liq
ikkThU3JL2PtvpQdAhw1K9PkoBTZJi-x

BaseAdapter-ni kengaytiradigan maxsus adapter kodi:
public class CustomAdapter extends BaseAdapter {

@Override


public int getCount() {
return 0;
}

@Override


public Object getItem(int i) {
return null;
}

@Override


public long getItemId(int i) {
return 0;
}

@Override


public View getView(int i, View view, ViewGroup viewGroup) {

return null;


}
Yuqoridagi kod parchasida biz BaseAdapter-ning bekor qilingan funksiyalarini ko‘ramiz, ular ro‘yxat, panjara yoki spinnerda ma'lumotlarni o‘rnatish uchun ishlatiladi. Ushbu funktsiyalar BaseAdapter qo‘llanmasida misol bilan tasvirlangan.
2. Androidda ArrayAdapter:
Agar bizda massiv tomonidan qo‘llab-quvvatlanadigan bitta elementlar ro‘yxati bo‘lsa, biz ArrayAdapter-dan foydalanishimiz mumkin. Masalan, telefon aloqalari, mamlakatlar yoki nomlar ro‘yxati.
Android ArrayAdapter qanday ko‘rinishga ega:
ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)
Yuqoridagi funktsiya ArrayAdapter qo‘llanmasida misol bilan tasvirlangan.
3. Androidda maxsus ArrayAdapter:
ArrayAdapter ham BaseAdapter dasturidir, shuning uchun agar biz ko‘proq moslashtirishni xohlasak, biz maxsus adapter yaratishimiz va unda ArrayAdapterni kengaytirishimiz mumkin. Massiv adapteri BaseAdapter ilovasi bo‘lganligi sababli, biz maxsus adapterimizda BaseAdapterning barcha funksiyalarini bekor qilishimiz mumkin.
Quyida MyAdapter maxsus adapter sinfi ArrayAdapter-ni quyidagicha kengaytiradi:
public class MyAdapter extends ArrayAdapter {

public MyAdapter(Context context, int resource, int textViewResourceId, List objects) {


super(context, resource, textViewResourceId, objects);
}
@Override
public int getCount() {
return super.getCount();
}

@Override


public View getView(int position, View convertView, ViewGroup parent) {
return super.getView(position, convertView, parent);
}
}
Ushbu funktsiyalar Custom ArrayAdapter qo‘llanmasida misol bilan tasvirlangan.

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6




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