Im trying to set an OnDragListener to certain words of a TextView using SpannableString. Im able to add an OnClick Listener by using ClickableSpan
by doing
hashText.setSpan(new ClickableSpan() {
So I figured I would try the same but replace ClickableSpan with OnDragListener.
I'm able to read the different drag events, but I have not been able to isolate the drag events to the specific words I choose, as Im able to do with ClickableSpan.
hashText.setSpan(new View.OnDragListener() {
@Override
public boolean onDrag(View targetView, DragEvent event) {
int action = event.getAction();
TextView targetVariable = (TextView) targetView;
String textGetter;
textGetter = targetVariable.getText().toString();
// boolean actionDropOutside = (DragEvent.ACTION_DRAG_ENDED != DragEvent.ACTION_DROP);
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
Log.d(TAG, "DRAG STARTED");
break;
case DragEvent.ACTION_DRAG_ENTERED:
////create method that checks if text is empty if so lights up
//if (textGetter.equals("")) {
targetView.setBackgroundColor(CARD_SLECTED);
//lightupVariableCard(cardV);
Log.d(TAG, "DRAG ENTERED EMPTY TEXT");
//}
Log.d(TAG, "DRAG ENTERED" + targetVariable.getText().toString());
break;
case DragEvent.ACTION_DRAG_EXITED:
targetView.setBackgroundColor(CARD_UNSLECTED);
Log.d(TAG, "DRAG EXITED");
break;
case DragEvent.ACTION_DROP:
// Dropped, reassign View to ViewGroup
//if (textGetter.equals("")) {
TextView draggedView = (TextView) event.getLocalState();
ViewGroup owner = (ViewGroup) draggedView.getParent();
targetVariable.setText(draggedView.getText());
owner.setVisibility(View.INVISIBLE);
targetView.setBackgroundColor(CARD_UNSLECTED);
//fabDisplayCounter++;
//displayFab();
Log.d(TAG, "DRAG DROPPED");
//}
Log.d(TAG, "DRAG NOT POSSSIBLE HERE");
break;
case DragEvent.ACTION_DRAG_ENDED:
// if (actionDropOutside == true){
// Log.d(TAG, "DRAG DROPPED OUTSIDE TRUE");
// }
Log.d(TAG, "DRAG ENDED");
//default:
}
return true;
}
}, matcher.start(), matcher.end(), i);
the_question.setText(hashText);
the_question.setMovementMethod(LinkMovementMethod.getInstance());
//the_question.setOnDragListener(new MyDragListener(hashText.nextSpanTransition()));