1

我目前是android编程的新手。我在我的代码中使用网格视图时遇到问题。我的代码目的是将一个图标与网格视图中的另一个图标交换。目前,我正在实现 onlongclick 方法来启动和拖动图标。我在 1 列中有 4 个图标,它们来自一个数组。触发 onlongclick 方法时,每个视图都将不可见。但是,当我在第一个图标上尝试时,视图变得不可见并且拖动方法没有开始。你能告诉我我在这部分做错了什么吗?这是错误日志。

08-04 22:53:50.460: E/SpannableStringBuilder(25556): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-04 22:53:50.460: E/SpannableStringBuilder(25556): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-04 22:53:51.990: E/View(25556): Unable to initiate drag
08-04 22:53:51.990: E/View(25556): java.lang.NullPointerException
08-04 22:53:51.990: E/View(25556):  at android.view.View.startDrag(View.java:16249)
08-04 22:53:51.990: E/View(25556):  at com.example.robotbehaviorui.CustomBehaviorActivity$MyLongClickListener.onItemLongClick(CustomBehaviorActivity.java:166)
08-04 22:53:51.990: E/View(25556):  at android.widget.AbsListView.performLongPress(AbsListView.java:3143)
08-04 22:53:51.990: E/View(25556):  at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:3093)
08-04 22:53:51.990: E/View(25556):  at android.os.Handler.handleCallback(Handler.java:615)
08-04 22:53:51.990: E/View(25556):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-04 22:53:51.990: E/View(25556):  at android.os.Looper.loop(Looper.java:137)
08-04 22:53:51.990: E/View(25556):  at android.app.ActivityThread.main(ActivityThread.java:4898)
08-04 22:53:51.990: E/View(25556):  at java.lang.reflect.Method.invokeNative(Native Method)
08-04 22:53:51.990: E/View(25556):  at java.lang.reflect.Method.invoke(Method.java:511)
08-04 22:53:51.990: E/View(25556):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
08-04 22:53:51.990: E/View(25556):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
08-04 22:53:51.990: E/View(25556):  at dalvik.system.NativeStart.main(Native Method)

这是我的 onlongclick 监听器

private final class MyLongClickListener implements AdapterView.OnItemLongClickListener{

@Override
public boolean onItemLongClick(AdapterView<?> arg0, View v,
        int arg2, long arg3) {
    try{
        Toast.makeText(CustomBehaviorActivity.this, "OnLongClick:  "+(CharSequence) v.getTag(), Toast.LENGTH_SHORT).show();
        ClipData data = ClipData.newPlainText("", "");
        DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
        v.startDrag(data, shadowBuilder, v, 0);
        v.setVisibility(v.INVISIBLE); 

        System.out.println("INDEX: "+ conditionsPanel.indexOfChild(v));
        System.out.println("SIZE: "+ conditionsList.size());
        System.out.println("COUNT: "+ conditionsAdapter.getCount());
        //pop up remove area
        deleteView.setVisibility(deleteView.VISIBLE);

    }catch(NullPointerException npe){
        System.out.println("NullPointerException: "+npe.getMessage());
    }catch(Exception exe){
        System.out.println("NullPointerException: "+exe.getMessage());
    }
    return true;
}

}

4

0 回答 0