Sto tentando di impostare un su TextView
utilizzando SpannableString
. Im in grado di aggiungere un OnClick
ascoltatore utilizzando ClickableSpan
Imposta Listener di trascinamento su SpannableString
facendo
hashText.setSpan(new ClickableSpan() {
così ho pensato che avrei provato lo stesso, ma sostituirlo con ClickableSpan
OnDragListener
.
Sono in grado di leggere i diversi eventi di trascinamento, ma non sono stato in grado di isolare gli eventi di trascinamento sulle parole specifiche che scelgo, in quanto sono in grado di fare con 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()));
Hey, grazie per il feedback. Non sto marcando come risposta perché non voglio essere sgridato dai mod, ma sono andato avanti e ho votato per assicurarti di ottenere punti per il tuo impegno. Ho armeggiato un po 'con il tuo suggerimento, ma nel frattempo sono andato in una direzione diversa. Non appena avrò tempo, rivedrò il tuo suggerimento e aggiungerò la soluzione in base alla tua risposta. Grazie ancora – user1446988
@ user1446988 nessun problema di accoppiamento, prova a rispondere alla tua domanda con la soluzione che hai trovato, può aiutare gli altri o anche il tuo sé futuro. Se provi il mio suggerimento fammelo sapere. –