OnClickItemListener en spinner en recycler ver android

Creo un elemento, donde solo tengo spinner:

class ItemSelect constructor(val list: ArrayList<String>) : AbstractItem<ItemSelect, ItemSelect.ViewHolder>() { override fun getType(): Int { return R.id.itemSpinner } override fun getLayoutRes(): Int { return R.layout.item_select } override fun bindView(holder: ViewHolder, payloads: MutableList<Any>?) { super.bindView(holder, payloads) val spinnerAdapter = ArrayAdapter<String>(holder.context, android.R.layout.simple_spinner_item) spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) spinnerAdapter.addAll(list) holder.spinner.adapter = spinnerAdapter holder.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { } override fun onNothingSelected(parent: AdapterView<*>) { } } } override fun unbindView(holder: ViewHolder) { super.unbindView(holder) } override fun getViewHolder(v: View): ViewHolder { return ViewHolder(v) } class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { val spinner: Spinner = view.itemSpinner val context: Context = view.context } } 

El artículo se agrega a la vista de reciclador.

Cuando quiero mostrar esta vista, recibí un error:

java.lang.RuntimeException: no llame a setOnClickListener para un AdapterView. Probablemente quieras setOnItemClickListener en su lugar

Error:

 java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead at android.widget.AdapterView.setOnClickListener(AdapterView.java:808) at com.mikepenz.fastadapter.utils.EventHookUtil.attachToView(EventHookUtil.java:58) at com.mikepenz.fastadapter.FastAdapter.onCreateViewHolder(FastAdapter.java:608) at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6488) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5675) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5558) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5554) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1516) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:608) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3694) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3411) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3963) at android.view.View.layout(View.java:19586) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791) at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1780) at android.widget.LinearLayout.onLayout(LinearLayout.java:1546) at android.view.View.layout(View.java:19586) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:19586) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:443) at android.view.View.layout(View.java:19586) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at android.view.View.layout(View.java:19586) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1791) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1635) at android.widget.LinearLayout.onLayout(LinearLayout.java:1544) at android.view.View.layout(View.java:19586) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323) at android.widget.FrameLayout.onLayout(FrameLayout.java:261) at com.android.internal.policy.DecorView.onLayout(DecorView.java:758) at android.view.View.layout(View.java:19586) at android.view.ViewGroup.layout(ViewGroup.java:6053) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2484) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2200) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911) at android.view.Choreographer.doCallbacks(Choreographer.java:723) at android.view.Choreographer.doFrame(Choreographer.java:658) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6541) at java.lang.reflect.Method.invoke(Native Method) 11-20 15:01:16.691 6942-6942/pl.skillforce.formsandroid E/AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 

    Prueba esto

     yourSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(Spinner parent, View view, int position, long id) { } }); 

    El error es claro, debe usar setOnItemClickListener que le devuelve el índice del elemento en el que se hizo clic.

    setOnClickListener es para

    Registre una callback que se invocará cuando se click esta vista. Si no se puede hacer clic en esta vista, se puede hacer clic en ella.

    y setOnItemClickListener

    Registre una callback que se invocará cuando se click un elemento de este AdapterView.

    así que testing:

     spinner.setOnItemClickListener( {parent, view, position, id -> "Item $position clicked" })