Reputation:
I am trying to do ListView
reordering with drag and drop, and I'm using the DevBytes example as a base. onTouch()
doesn't get called on my ListView when I touch the drag handle, that is, a child of one of the ListView
's children.
As this didn't work, on my Adapter
's getView()
, I tried doing the following:
@Override
public View getView(final int position, View view, final ViewGroup parent) {
ViewHolder holder;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (view != null) {
holder = (ViewHolder) view.getTag();
} else {
view = inflater.inflate(R.layout.store_list_item, parent, false);
holder = new ViewHolder(view);
view.setTag(holder);
}
holder.storeName.setText(mShoppingLists.get(position).getName());
holder.editButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final FragmentManager manager = ((Activity) mContext).getFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
ShoppingListEditFragment shoppingListEditFragment =
ShoppingListEditFragment.newInstance(mShoppingLists.get(position).getId());
transaction.replace(R.id.container, shoppingListEditFragment, "shoppinglistedit");
transaction.addToBackStack(null);
transaction.commit();
}
});
holder.handle.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
((DynamicListView) parent).onHandleLongClickListener(new DragEvent());
return false;
}
});
return view;
}
This partially works, but as the touch listener only triggers for touches, and not for when the touch ends, this doesn't work properly. Why does this happen?
Upvotes: 0
Views: 303
Reputation: 2566
The touch listener is only giving you action_down events because you are returning false. If you return true you will also be sent corresponding action_move and action_up/action_cancel actions.
I can't remember which page of the documentation states this, otherwise I would link to it.
Upvotes: 2