gpt4 book ai didi

android - 拖动但清空剪辑数据

转载 作者:行者123 更新时间:2023-11-29 18:10:10 26 4
gpt4 key购买 nike

我找不到问题出在哪里,我想我把东西放到了 item 和 clipdata 中,但是我的 onDrag 总是收到空指针异常,甚至无法获取项目数。

这是我的 OnDragListener 类

    public class ScaleImageSize implements View.OnDragListener{

@Override
public boolean onDrag(View arg0, DragEvent arg1) {
// TODO Auto-generated method stub
final int action = arg1.getAction();
Integer tag = (Integer) arg0.getTag();
Log.d("tag",Integer.toString(tag));

int count = arg1.getClipData().getItemCount();
Log.d("count",Integer.toString(count));


ClipData.Item item = arg1.getClipData().getItemAt(0);
String tagString = item.getText().toString();
int tagOfType = Integer.valueOf(tagString);

switch(action){

case DragEvent.ACTION_DRAG_STARTED:

return true;
case DragEvent.ACTION_DRAG_LOCATION:
augImg( tag, (int) arg1.getY());

augImg( tagOfType, (int)arg1.getY());

return true;
case DragEvent.ACTION_DROP:

return true;
}
return false;
}

};

这是我的 OnLonClickListener 类,它应该调用函数 startdrag。

       OnLongClickListener StartScaleImageSize = new OnLongClickListener(){

@Override
public boolean onLongClick(View v) {
// TODO Auto-generated method stub
int i = (Integer) v.getTag();
beingLongClick[i] = true;

ClipData.Item item = new ClipData.Item((CharSequence)Integer.toString(i));
String[] clipDescription = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipData dragData = new ClipData((CharSequence)Integer.toString(i),
clipDescription,
item);
dragData.addItem(item);

DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
v.startDrag(dragData, shadowBuilder, v, 0);
return false;
}
};

错误信息:

06-24 21:47:21.205: E/AndroidRuntime(4123): FATAL EXCEPTION: main
06-24 21:47:21.205: E/AndroidRuntime(4123): java.lang.NullPointerException
06-24 21:47:21.205: E/AndroidRuntime(4123): at traveler.com.TravelerpActivity$TypeMgr$ScaleImageSize.onDrag(TravelerpActivity.java:237)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.View.dispatchDragEvent(View.java:13619)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewGroup.notifyChildOfDrag(ViewGroup.java:1287)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1131)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewGroup.notifyChildOfDrag(ViewGroup.java:1287)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1131)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewGroup.notifyChildOfDrag(ViewGroup.java:1287)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1131)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewGroup.notifyChildOfDrag(ViewGroup.java:1287)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1131)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewRootImpl.handleDragEvent(ViewRootImpl.java:3471)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2620)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.os.Looper.loop(Looper.java:137)
06-24 21:47:21.205: E/AndroidRuntime(4123): at android.app.ActivityThread.main(ActivityThread.java:4441)
06-24 21:47:21.205: E/AndroidRuntime(4123): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 21:47:21.205: E/AndroidRuntime(4123): at java.lang.reflect.Method.invoke(Method.java:511)
06-24 21:47:21.205: E/AndroidRuntime(4123): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-24 21:47:21.205: E/AndroidRuntime(4123): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-24 21:47:21.205: E/AndroidRuntime(4123): at dalvik.system.NativeStart.main(Native Method)

请给我任何建议,谢谢!

最佳答案

尝试以这种方式创建 dragData:

ClipData dragData = ClipData.newPlainText("simple text", toString(i));

关于android - 拖动但清空剪辑数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11178079/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com