どこに問題があるのか わかりません。アイテムとクリップデータに正しく入れたと思いますが、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;
}
};
これは、関数 startdrag を呼び出す必要がある OnLonClickListener クラスです。
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)
pls、どんなアドバイスでも大歓迎です!