如何使用kotlin单击listView项目中的imageButton后才能获取DB ID

我有一个customAdapter类和一个listView。 我做了3个textview和一个imageButton的single_row布局。 现在我的问题是我怎么能得到DB ID字段,只能从单击imageButton并忽略整个行上的点击? 我知道我可以得到的ID:

mListView.onItemClickListener = AdapterView.OnItemClickListener { adapterView, view, position, id -> view.delete.setOnClickListener(){ Toast.makeText(context,""+id,Toast.LENGTH_SHORT).show() } 

但是这只有当我点击整个行时才有效。 我在imageButton节点中的xml和android:focusable="false" focusable android:focusable="false"的根目录中尝试了android:descendantFocusability="blocksDescendants" ,并且在整个行被识别时imageButton无法识别。 只有当我使用button.onClickListener()...点击被识别。 但这样我不知道如何得到身份证。

我的适配器类代码:

 class MyAdapter(activity: Activity, context: Context, cursor: Cursor) : CursorAdapter(context, cursor, true) { var inflater: LayoutInflater lateinit var mListView: ListView init { this.inflater = LayoutInflater.from(context) mListView = activity.listView } override fun newView(context: Context?, cursor: Cursor?, parent: ViewGroup?): View { val view = LayoutInflater.from(context).inflate(R.layout.single_row, parent, false) return view; } override fun bindView(view: View, context: Context, cursor: Cursor) { val latitude = view.findViewById(R.id.latitude) as TextView val longtitude = view.findViewById(R.id.longtitude) as TextView val date = view.findViewById(R.id.date) as TextView val asu = view.findViewById(R.id.asu) as TextView latitude.setText(cursor.getString(cursor.getColumnIndex(Constants.Signal.LATITUDE))) longtitude.setText(cursor.getString(cursor.getColumnIndex(Constants.Signal.LONGTITUDE))) date.setText(cursor.getString(cursor.getColumnIndex(Constants.Signal.DATE))) asu.setText(cursor.getString(cursor.getColumnIndex(Constants.Signal.ASU))) } } 

我的single_row布局:

         

您正在使用游标适配器,您应该使用ArrayAdapter。 这是为什么自定义cursoradapter和为什么不使用和ArrayAdapter的例子