listview.pointToPosition不应该提供INVALID值

时间:2015-01-26 22:15:37

标签: android android-listview drag-and-drop

我从生产中的应用程序获取信息,但是当我尝试重现问题时,我无法做到。我正在寻找的是我如何尝试重现错误的任何想法(因为我被阻止)。

基本上我正在使用listview,toolbar,edittext和admob广告进行活动。

我的列表视图由一个包含textview和一个imageview的relativealayout组成。

使用我附加到textview的适配器OnLongClickListener来启动拖动操作。

对于Listview本身,我正在添加一个OnDragListener。

 @TargetApi(11)
 public class myDragEventListener implements View.OnDragListener {
        // This is the method that the system calls when it dispatches a drag event to the
        // listener.
        public boolean onDrag(View v, DragEvent event) {
            // Defines a variable to store the action type for the incoming event
            final int action = event.getAction();
            // Handles each of the expected events
            switch(action) {
                case DragEvent.ACTION_DRAG_STARTED:
                    return true;
                case DragEvent.ACTION_DROP:
                    //We detect which is the item where the drop happened on.
                    int itemPosition = listShop.pointToPosition((int)event.getX(), (int)event.getY());

                // An unknown action type was received.
                default:
                    return true;
            }
        }
    }

因此,基本上我们从listview项开始拖动textview,并且dropview在listview本身结束。

此代码工作正常,但我从生产报告中收到有时itemPosition的值为-1。为了避免异常,我可以添加一个简单的检查,但我担心用户体验。

所以,我想避免的是用户体验不正确,应用程序没有正确响应,我们知道由于报告而发生。问题是我们无法重现。

尝试重现我们尝试过的错误:

  • Longclick on textview并放在imageview上。 (提供正确的itemPosition)
  • Longclick on textivew并在listview外部删除(拖动侦听器未调用)
  • Longclick on textivew并放在listview的边缘(工作正常)。

有人建议如何使用这个" -1"可以复制?从理论上讲它不应该发生....是丢弃(无论已经启动的拖动)激活OnDragListener,这意味着发生丢弃的位置是列表视图的位置。如何在列表视图中以不正确的位置调用DragListener?

知道会发生什么事吗?

1 个答案:

答案 0 :(得分:0)

好的,我发现了问题。我的列表视图几乎覆盖了所有屏幕,有时候列表中的项目不会覆盖整个列表,直到最后。当项目在列表中没有项目的空间中拖放时,请提供该值。

问题在于,与其他设备相比,我的测试移动设备非常小,并且移动设备始终将屏幕完全覆盖在列表中,因此始终捕获任何拖放操作。