Skip to content

onDataClickListener and onDataLongClickListener #207

Description

@SennyK22

Hello. I'm have problem with listeners.

In my code I'm have that:

tableView.addDataClickListener { rowIndex, clickedData ->
                clickedData as Array<String>
                onResume()
                FancyToast.makeText(
                    this,
                    "Szkolenie: " + clickedData[0] + "\nDzień: " + clickedData[1] + "\nProwadzący: " + clickedData[3],
                    FancyToast.LENGTH_LONG,
                    FancyToast.INFO,
                    false
                ).show()
        }
        tableView.addDataLongClickListener { rowIndex, clickedData ->
                // Utwórz menu kontekstowe

                val popup = PopupMenu(this, View(this))
                popup.inflate(R.menu.contex_menu)

                // Ustaw listener dla pozycji menu
                popup.setOnMenuItemClickListener { item ->
                    when (item.itemId) {
                        R.id.context_menu_edit -> {
                            // Kod dla pierwszej pozycji menu
                            Toast.makeText(this, "Edycja" + rowIndex, Toast.LENGTH_SHORT).show() as Boolean
                        }
                        R.id.context_menu_info -> {
                            // Kod dla drugiej pozycji menu
                            Toast.makeText(this, "Info" + rowIndex, Toast.LENGTH_SHORT).show() as Boolean
                        }
                        else -> return@setOnMenuItemClickListener false
                    }
                    wasLongClick = true
                    true
                }

                // Wyświetl menu kontekstowe
                popup.show()

            Toast.makeText(this, "dsadas" + rowIndex, Toast.LENGTH_SHORT).show() as Boolean
            true
        }

And when Im do long click first that show me action on LongClickListener and then action on ClickListener...

What I'm can do show me only LongListener when do long click ?

Activity

  1. ISchwarz23 commented on Feb 12, 2023

    @ISchwarz23
    Owner

    Hey, if you return true fromt the TableDataLongClickListener callback, the TableDataClickListener should not be called.

  2. SennyK22 commented on Feb 13, 2023

    @SennyK22
    Author

    Hi.
    Yes, I know it should be, but as you can see, my code has a return true and it does both.
    If I longclick and drag my finger somewhere then there is no onClickListener only onLongClickListener

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions