@@ -20,29 +20,31 @@ class AutoCompleteTextViewAdapter(val activity: SimpleActivity, val contacts: Ar
2020 var resultList = ArrayList <SimpleContact >()
2121
2222 override fun getView (position : Int , convertView : View ? , parent : ViewGroup ): View {
23- val contact = resultList[ position]
23+ val contact = resultList.getOrNull( position)
2424 var listItem = convertView
25- if (listItem == null || listItem.tag != contact.name.isNotEmpty()) {
25+ if (listItem == null || listItem.tag != contact? .name? .isNotEmpty()) {
2626 listItem = LayoutInflater .from(activity).inflate(R .layout.item_contact_with_number, parent, false )
2727 }
2828
2929 listItem!! .apply {
30- tag = contact.name.isNotEmpty()
30+ tag = contact? .name? .isNotEmpty()
3131 // clickable and focusable properties seem to break Autocomplete clicking, so remove them
3232 findViewById<View >(R .id.item_contact_frame).apply {
3333 isClickable = false
3434 isFocusable = false
3535 }
3636
3737 val backgroundColor = activity.config.backgroundColor
38- findViewById<TextView >(R .id.item_contact_name).text = contact.name
39- findViewById<TextView >(R .id.item_contact_number).text = contact.phoneNumbers.first()
4038 findViewById<RelativeLayout >(R .id.item_contact_holder).setBackgroundColor(backgroundColor.darkenColor())
4139
4240 findViewById<TextView >(R .id.item_contact_name).setTextColor(backgroundColor.getContrastColor())
4341 findViewById<TextView >(R .id.item_contact_number).setTextColor(backgroundColor.getContrastColor())
4442
45- SimpleContactsHelper (context).loadContactImage(contact.photoUri, findViewById(R .id.item_contact_image), contact.name)
43+ if (contact != null ) {
44+ findViewById<TextView >(R .id.item_contact_name).text = contact.name
45+ findViewById<TextView >(R .id.item_contact_number).text = contact.phoneNumbers.first()
46+ SimpleContactsHelper (context).loadContactImage(contact.photoUri, findViewById(R .id.item_contact_image), contact.name)
47+ }
4648 }
4749
4850 return listItem
0 commit comments