0

I would like to add a gesture to my recyclerview, which detect a click of 5 seconds and that after 5 seconds it executes a method.

On iOS, in Swift, here is my code:

func setupLongPressGesture() {
    let longPressGesture:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongPress))
    longPressGesture.minimumPressDuration = 1.0 // 1 second press
    longPressGesture.delegate = self as? UIGestureRecognizerDelegate
    usersTableView.addGestureRecognizer(longPressGesture)
}

@objc func handleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer){

    displayProfile = false;
    navItemSelected.isHidden = false; //La nav du bas

    //On le programme en .began pour executer la methode meme si le doight est encore sur l'ecran. Le .end c'est quand le doight s'enleve de l'ecran
    if gestureRecognizer.state == .began {
        let touchPoint = gestureRecognizer.location(in: self.usersTableView)

        if let indexPath = usersTableView.indexPathForRow(at: touchPoint)?.row {
            ViewController.selectedUsers.append(users[indexPath]);
            countSelected.text = "(\(ViewController.selectedUsers.count))";
        }
    }

    usersTableView.reloadData()
}

I want the same for Android.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253

0 Answers0