我的OnClickListener仅在第二次单击时被调用。同一View的OnLongClickListener可以正常工作。我尝试使用OnTouchListener代替,但是刷卡时显然会触发该事件。我的侦听器是我在活动中实现的接口的抽象方法:interface OnVocableFlashcardFragmentInteractionListener { fun onEditTextLongClick(view: View): Boolean fun onEditTextClick(view: View)}我在RecyclerViewAdapter类中这样设置View的侦听器:init{ setHasStableIds(true) mEditTextOnClickListener = View.OnClickListener { mListener.onEditTextClick(it) } mEditTextOnLongClickListener = View.OnLongClickListener { mListener.onEditTextLongClick(it) }}override fun onBindViewHolder(holder: FlashcardViewHolder, position: Int) { ... editText.let { it.tag = it.keyListener; it.keyListener = null; } editText.setOnClickListener(mEditTextOnClickListener) editText.setOnLongClickListener(mEditTextOnLongClickListener) ...}在我的活动中,侦听器的实现如下所示:override fun onEditTextClick(view: View) { //-- only show toast if view is not editable (becomes editable on LongClick) if ((view as EditText).keyListener == null) { if (mToast != null) { mToast!!.cancel() } //-- inform user to long press to edit entry mToast = Toast.makeText(this, resources.getString(R.string.long_click_to_edit), Toast.LENGTH_LONG) mToast!!.show() }}override fun onEditTextLongClick(view: View): Boolean { //-- I saved the KeyListener in the editTexts tag attribute //-- to make it clickable again when needed (view as EditText).keyListener = view.getTag() as KeyListener showSoftKeyboard(view) return true}视图的父母及其父母的父母未声明为 android:focusable="true"或android:clickable="true"在我的AndroidManifest.xml中,我android:windowSoftInputMode="stateHidden"为活动设置了设置,以防止活动开始时显示SoftInput。我是在做完全错误的事情,还是为什么只在第二次单击时才调用OnClickListener?有谁知道我该如何解决这个问题?
添加回答
举报
0/150
提交
取消