i have an edittext which contains SpannableString with text and ImageSpan, i would like when i long press on an ImageSpan to know which Drawable i clicked (or the index in SpannableString) and convert it to uri to copy it to clipboard. after that you can paste it in the other edittext. but i don't know how to deal with this problem.
here is my code if someone can help, thanks in advance
editText=(EditText)findViewById(R.id.editText);
SpannableString ss = new SpannableString("abcd efgh ijklmn opqr stuv wxy");
Drawable d = getResources().getDrawable(R.drawable.logomakr);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, 20, 21, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
ss.setSpan(new ClickableSpan() {
@Override
public void onClick(View v) {
new AlertDialog.Builder(MainActivity.this)
.setTitle("Copy Image")
.setPositiveButton("copy", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// continue with copy
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
}, 20, 21, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
editText.setText(ss);
editText.setMovementMethod(LinkMovementMethod.getInstance());