Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set on click listener and toast id item click? #59

Open
promahdimosavi opened this issue May 31, 2021 · 1 comment
Open

how to set on click listener and toast id item click? #59

promahdimosavi opened this issue May 31, 2021 · 1 comment

Comments

@promahdimosavi
Copy link

No description provided.

@ashrafimostafa
Copy link

Hi
I don't know why there is not enough documentation but it is possible to handle onClick(), onLongClick() or any other kind of action that you want.

To do that you should follow below steps:

  1. Add an interface to handle on click into ViewBinder like below:
     public BookViewBinder(View itemView, OnClick onClick) {
        super(itemView);
        this.onClick = onClick;
        rootView = itemView.findViewById(R.id.item_nest_book_root);
    }
  1. In bindView method use it like below:
    @Override
    public void bindView(TreeNode treeNode) {

        rootView.setOnLongClickListener(v -> {
            onClick.onBookLongClick((Book) (treeNode.getValue()));  //cast treeNode.value() to  prefered data type
            return true;
        });
    } 
  1. Then pass the interface instance through the ViewFactory constructor like below:

public class BookViewFactory extends BaseNodeViewFactory {

    OnClick onClick;

    public BookViewFactory(OnClick onClick) {
        this.onClick = onClick;
    }
  1. In the final step when you create new instance of BookViewFactory implement interface methods.

good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants