2015-08-28 35 views
0

我的总体目标是能够将一行从RecyclerView拖到我的应用程序中的另一个视图。为什么我的拖放操作在RecyclerView中失败?

使用带有LinearLayoutmanager的标准RecyclerView,没有额外的巨型巨型拖放操作,完美无瑕。然而,当我介绍叫AndroidSwipeLayout使每一行滑动式揭示额外的操作都失败定制库,我得到了普遍的错误:

08-28 09:59:03.465: I/ViewRootImpl(15310): Reporting drop result: false 

我也可以看到,这是在炒鱿鱼,DragEvents我接收视图是ACTION_DRAG_STARTEDACTION_DRAG_ENDED,所有其他事件都被跳过。正如你所看到的我从ACTION_DRAG_STARTED返回true,但这并没有帮助,我的想法是,自定义库以某种方式吃我的事件。但我无法确定在哪里。

这里是我的OnDragListener:

private class MyDropListener implements View.OnDragListener { 

    @Override 
    public boolean onDrag(View v, DragEvent event) { 
    // Doing some calculations based on event x and y. Not related to the problem. 

    switch (event.getAction()) { 
     case DragEvent.ACTION_DRAG_STARTED: 
     // Some unrelated code, updating how views are displayed 
     return true; 

     case DragEvent.ACTION_DRAG_LOCATION: 
     // Some unrelated code, updating how views are displayed 
     return true; 

     case DragEvent.ACTION_DROP: 
     // Some unrelated code, updating some data and updating how views are displayed 
     return true; 

     case DragEvent.ACTION_DRAG_ENDED: 
     // Some unrelated code, updating how views are displayed 
     return true; 

     case DragEvent.ACTION_DRAG_ENTERED: 
     // Some unrelated code, updating how views are displayed 
     return true; 

     case DragEvent.ACTION_DRAG_EXITED: 
     // Some unrelated code, updating how views are displayed 
     return true; 

     default: 
     return false; 
    } 
    } 
} 

现在我已经尝试了库内几天,但正是我的事件死亡找不到固溶体。有时候我已经设法让这个下降工作,但这是非常不规律的行为。

我也做了Github的问题,对于这个问题:

AndroidSwipeLayout - issue #211

我敢肯定,这不是针对这个库,但如果有太多的手势检测为每去一个问题在列表中查看。我认为这个图书馆非常出色,我不希望自己写这个互动。

任何想法或意见,欢迎和赞赏。即使你不知道确切的解决方案。

谢谢。

回答

0

这实际上不是由库或听众引起的,它是由位于相同布局中的EditText引起的。

它是通过创建一个新的类来实现的,该类继承了EditText并忽略了dragEvent。

public class EditTextNoDrag extends EditText { 

    public EditTextNoDrag(Context context) { 
    super(context); 
    } 

    public EditTextNoDrag(Context context, AttributeSet attrs) { 
    super(context, attrs); 
    } 

    public EditTextNoDrag(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
    } 

    public EditTextNoDrag(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 
    super(context, attrs, defStyleAttr, defStyleRes); 
    } 

    @Override 
    public boolean onDragEvent(DragEvent event) { 
    switch (event.getAction()) { 
     case DragEvent.ACTION_DRAG_STARTED: 
     return false; 
     default: 
     return super.onDragEvent(event); 
    } 
    } 
} 

您也可以打开和关闭EditText的可调焦状态。 看到这个相关的isseu:Prevent drag drop of custom mimetype to EditText