我目前是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;
}
}