(I deleted all code, because the below code is not working either.)
Additional information and short summary - the real problem
This is interesting. I have another project a simple activity. There, I can drag. Now in this project, I block commented everywhere. There are only a few lines, like another project, but still no drag.
Drag is in progress, but there is no drag window handle.
Sometimes it says. I also searched it, but I could not do it.
The code is now:
protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "matching ggame OnCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_matchgame);
setupForGame();
Log.d(TAG, "matching game OnCreate ends");
}//oncreate end
void setupForGame(){
Log.d(TAG, "matching game setupforgame");
imageAnswer = (ImageView) findViewById(R.id.imgAnswer);
imageAnswer = (ImageView) findViewById(R.id.imgAnswer);
}
public boolean onTouch(View view, MotionEvent motionEvent) {
Log.d(TAG, "ontouch never");
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, shadowBuilder, view, 0);
view.setVisibility(View.INVISIBLE);
return true;
}
else {
return false;
}
}
@Override
public boolean onDrag(View receivingLayoutView, DragEvent dragEvent) {
Log.d(TAG, "ondrag start");
And still not going inside.
I made it static to see if that is the problem.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/relative_layout"
tools:context=".games.MatchingGame">
<ImageView
android:id="@+id/imgAnswer"
android:layout_width="111dp"
android:layout_height="111dp"
android:src="@drawable/b3_1"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
/>
</RelativeLayout>
It is same as another project, but it is not working. I looked at all possibilities and debugged.
And please don't ask for drag method code; it is not important. It can't enter it.
When I hold and drag image, this comes to the log in a loop until I leave:
I/SPRDHWComposer: util[1759] warning: osdLayer width 111, stride 112, not equal!
And when I leave the image:
V/WindowManager: rotationForOrientationLw(orient=0, last=1); user=0 USER_ROTATION_LOCKED sensorRot
V/WindowOrientationListener: getProposedRotation : mEnabled = false, mUsedautorotioansensor =true
W/WindowManager: Drag is in progress but there is no drag window handle.
I also made this if the touch is problem, but it is still the same:
imageAnswer.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//if (event.getAction() == MotionEvent.ACTION_DOWN) { Log.d(TAG, "ontouch down");
//Log.d(TAG,"parent "+ String.valueOf(img1.getParent()));
Log.d(TAG, "view "+String.valueOf(v));
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
v.startDrag(data, shadowBuilder, v, 0);
v.setVisibility(View.INVISIBLE);
return true;
This is my old project that works with drag and drop. I can't see the difference:
https://gist.github.com/anonymous/540a70e05de6d765e20896b47deb7eb2
When I do this
imageAnswer.setOnDragListener(new View.OnDragListener() {
public boolean onDrag(View v, DragEvent event) { Log.d(TAG, "drag");
return false;
}
});
It does not work either. No log.
Also this does not give a log:
imageAnswer.setOnDragListener(new dropListener());
private class dropListener implements View.OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {Log.d("Chic","ondrag");
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
break;
case DragEvent.ACTION_DRAG_ENDED:
break;
default:
break;
}
return true;
}
}
There is difference between the two projects:
Can this be the reason?
I tried also to put all setondrag setontouch inside oncreate.