我正在开发一个应用程序,用户可以从图库中选择一张图片并将其添加到编辑框中。现在,如果用户在编辑框中点击图片,它应该在全屏模式下打开。我使用了以下代码:
public void addToEdt(Bitmap bitmap){
SpannableString ss = new SpannableString("abc");
Drawable d = new BitmapDrawable(getResources(), bitmap);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, 0, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
edt_note.setTransformationMethod(null);
edt_note.getText().insert(edt_note.getSelectionStart(), ss);
final int start = ss.getSpanStart(span);
final int end = ss.getSpanEnd(span);
ClickableSpan click_span = new ClickableSpan() {
@Override
public void onClick(View widget) {
Toast.makeText(getApplicationContext(),"Clicked",Toast.LENGTH_LONG).show();
}
};
ClickableSpan[] click_spans = ss.getSpans(start, end, ClickableSpan.class);
if(click_spans.length != 0) {
// remove all click spans
for (ClickableSpan c_span : click_spans) {
ss.removeSpan(c_span);
}
}
ss.setSpan(click_span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
我尝试了上面的代码,但它没有响应onClick事件,现在我该如何监听这张图片的点击事件并执行进一步的任务?