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

Cannot click on item without dragging #40

Closed
tranhoainam opened this issue Nov 3, 2016 · 4 comments
Closed

Cannot click on item without dragging #40

tranhoainam opened this issue Nov 3, 2016 · 4 comments

Comments

@tranhoainam
Copy link

Hi,

I have an EditText inside the drag item. I want to edit that EditText when I click on it and drag the item with a long-click but it's currently seems impossible to me. It starts to drag when I click it (without having to "long-click").

I tried to force onItemLongClicked (of the viewholder) to return false or true but neither works. I also tried setting the grabhandle to the container layout of the whole item (the current grabhandle is the EditText) but then I can't always drag (maybe because the child views almost fill the container), but even if I can drag the item, it's "click to drag" not "long-click to drag".

Am I missing something here? How can I accomplish it?

Thank you.

@woxblom
Copy link
Owner

woxblom commented Nov 4, 2016

Hey,

You need to pass true to the super class in the viewholder to make it drag on longpress.

`public class ViewHolder extends DragItemAdapter.ViewHolder {
public TextView mText;

public ViewHolder(final View itemView) {
    super(itemView, mGrabHandleId, mDragOnLongPress); <<<<------ HERE
    mText = (TextView) itemView.findViewById(R.id.text);
}

@Override
public void onItemClicked(View view) {
    Toast.makeText(view.getContext(), "Item clicked", Toast.LENGTH_SHORT).show();
}

@Override
public boolean onItemLongClicked(View view) {
    Toast.makeText(view.getContext(), "Item long clicked", Toast.LENGTH_SHORT).show();
    return true;
}

}`

@tranhoainam
Copy link
Author

Hi,

I tried that also but the super method doesn't take the 3rd argument.

This is my ViewHolder:

`public class ViewHolder extends DragItemAdapter<Pair<Long, ConvertedChecklist>, ViewHolder>.ViewHolder{
int type;
public ViewHolder(final View itemView, int grab, int viewType) {
super(itemView, grab); //This line wont accept a "true" argument
type = viewType;
}

    @Override
    public void onItemClicked(View view) {

    }

    @Override
    public boolean onItemLongClicked(View view) {
       return true;
    }
}`

@tranhoainam
Copy link
Author

Oh, it turns out I've passed false for the constructor when I created the Adapter. Set it to true fixed my problem.

Thank you for pointing out what I'm doing wrong :D

@woxblom
Copy link
Owner

woxblom commented Nov 4, 2016

In the latest version of the lib I did some refactor, so now you do pass it in the viewholder, before you did it in the adapter constructor.

Glad to help :)

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