ipdan4ik

[lb7] ItemAdapter.kt

Apr 16th, 2021
727
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.lb7
  2.  
  3. import android.annotation.SuppressLint
  4. import android.content.Context
  5. import android.view.LayoutInflater
  6. import android.view.View
  7. import android.view.ViewGroup
  8. import android.widget.BaseAdapter
  9. import android.widget.TextView
  10.  
  11. class ItemAdapter(context: Context, items: ArrayList<Item>):
  12.     BaseAdapter() {
  13.     var ctx: Context = context
  14.     var objects: ArrayList<Item> = items
  15.     var inflater: LayoutInflater = ctx.
  16.     getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
  17.     @SuppressLint("SetTextI18n")
  18.     override fun getView(position: Int, convertView: View?,
  19.                          parent: ViewGroup?): View {
  20.         var view = convertView
  21.         if (view == null)
  22.             view = inflater.inflate(R.layout.listview_layout_item,
  23.                 parent, false)
  24.         val s = objects[position]
  25.         var v = view?.findViewById(R.id.item_title) as TextView
  26.         v.text = s.title
  27.         v = view.findViewById(R.id.item_coordinates) as TextView
  28.         v.text = "${s.latitude}, ${s.longitude}"
  29.         return view
  30.     }
  31.     // Получение элемента данных в указанной строке
  32.     override fun getItem(position: Int): Any {
  33.         return objects[position]
  34.     }
  35.     // Получение идентификатора элемента в указанной строке
  36.     // Часто вместо него возвращается позиция элемента
  37.     override fun getItemId(position: Int): Long {
  38.         return position.toLong()
  39.     }
  40.     // Получение количества элементов в списке
  41.     override fun getCount(): Int {
  42.         return objects.size
  43.     }
  44. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×