I use custom adapter for List View on my android app . I do not know how can set the listener for the item click. I use Kotlin for my app.
This is my adapter layout.
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"><RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"><CheckBox android:id="@+id/cbx" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /><TextView android:id="@+id/txtNameNote" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView" android:layout_toRightOf="@+id/cbx" /><TextView android:id="@+id/txtPercent" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="TextView" android:layout_toRightOf="@+id/cbx" android:layout_below="@+id/txtNameNote" /></RelativeLayout></LinearLayout>
class CustomAdapter(internal var context: Context, resource: Int, internal var listNote: ArrayList<Note>) : ArrayAdapter<Note>(context, resource, listNote) { override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { var convertView = convertView // TODO Auto-generated method stub val inflater = (context as Activity).layoutInflater convertView = inflater.inflate(R.layout.rowlistitem, parent, false) val name = convertView!!.findViewById<View>(R.id.txtNameNote) as TextView val percent = convertView.findViewById<View>(R.id.txtPercent) as TextView val cb = convertView.findViewById<View>(R.id.cbx) as CheckBox name.text = listNote[position].name percent.text = "Percent: "+ listNote[position].percent +"%" if (listNote[position].status == NoteStatus.Active.value) cb.isChecked = false else{ name.paintFlags = (name.paintFlags or Paint.STRIKE_THRU_TEXT_FLAG) cb.isChecked = true } } } return convertView }}
Some one can help me out ?