@@ -5,35 +5,36 @@ import android.view.LayoutInflater
55import android.view.View
66import android.view.ViewGroup
77import android.widget.BaseAdapter
8- import com.blogspot.e_kanivets.moneytracker.R
9- import kotlinx.android.synthetic.main.view_backup_item.view.ivDelete
10- import kotlinx.android.synthetic.main.view_backup_item.view.tvTitle
8+ import com.blogspot.e_kanivets.moneytracker.databinding.ViewBackupItemBinding
119
12- class BackupAdapter (private val context : Context , private val backups : List <String >) : BaseAdapter() {
10+ class BackupAdapter (
11+ private val context : Context ,
12+ private val backups : List <String >,
13+ ) : BaseAdapter() {
1314
1415 var onBackupListener: OnBackupListener ? = null
1516
1617 override fun getView (position : Int , convertView : View ? , parent : ViewGroup ? ): View {
18+ val binding: ViewBackupItemBinding
1719 var view = convertView
18- val viewHolder: ViewHolder ?
1920
2021 if (view == null ) {
2122 val layoutInflater = LayoutInflater .from(context)
2223
23- view = layoutInflater .inflate(R .layout.view_backup_item , parent, false )
24- viewHolder = ViewHolder (view)
24+ binding = ViewBackupItemBinding .inflate(layoutInflater , parent, false )
25+ view = binding.root
2526
26- view.tag = viewHolder
27+ view.tag = binding
2728 } else {
28- viewHolder = view.tag as ViewHolder
29+ binding = view.tag as ViewBackupItemBinding
2930 }
3031
3132 val backupItem = getItem(position)
3233
33- viewHolder.view .tvTitle.text = backupItem
34- viewHolder.view .ivDelete.setOnClickListener { onBackupListener?.onBackupDelete(backupItem) }
34+ binding .tvTitle.text = backupItem
35+ binding .ivDelete.setOnClickListener { onBackupListener?.onBackupDelete(backupItem) }
3536
36- return view!!
37+ return view
3738 }
3839
3940 override fun getItem (position : Int ): String = backups[position]
@@ -42,10 +43,7 @@ class BackupAdapter(private val context: Context, private val backups: List<Stri
4243
4344 override fun getCount (): Int = backups.size
4445
45- private data class ViewHolder (val view : View )
46-
4746 interface OnBackupListener {
4847 fun onBackupDelete (backupName : String )
4948 }
50-
5149}
0 commit comments