setOnCreateContextMenuListener не работает в RecycleView OnBindViewHolder - PullRequest
1 голос
/ 08 января 2020

Я использую setOnCreateContextMenuListener в onBindViewHolder, но прослушиватель контекстного меню не запускается, когда я использую setOnLongClickListener в onBindViewHolder.

override fun onBindViewHolder(holder: friendsAdapter.ListViewHolder, position: Int) {    
        holder.tvUsername.text = listFriends[position].username
        holder.tvEmail.text = listFriends[position].email        
        mBundle = Bundle()

        holder.itemView.setOnClickListener{
            mBundle.putString(friendProfile.EXTRA_ID, listFriends[position].id)
            mBundle.putString(friendProfile.EXTRA_USERNAME, listFriends[position].username)
            mBundle.putString(friendProfile.EXTRA_EMAIL, listFriends[position].email)
            mBundle.putString(friendProfile.EXTRA_IMAGE, listFriends[position].profilelink)
            profileFrag.profileData = mBundle
            fManager
                .beginTransaction()
                .replace(R.id.nav_host_fragment, profileFrag, friendProfile::class.java.simpleName)
                .addToBackStack(null)
                .commit()
        }

        holder.itemView.setOnLongClickListener{
            Toast.makeText(context, listFriends[position].id, Toast.LENGTH_SHORT).show()
            mBundle.putString(friendProfile.EXTRA_ID, listFriends[position].id)
            profileFrag.profileData = mBundle
            return@setOnLongClickListener true
        }

        holder.itemView.setOnCreateContextMenuListener(this)
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...