如何在Android中使用笔记记录应用程序附加多个图像?

时间:2015-11-23 20:27:10

标签: android

我正在尝试在Android中制作笔记应用程序,我完成了简单的笔记文本保存部分。现在,我正在尝试使用note附加图像(在edittext中)。我尝试使用spannable来实现这个东西但是不能处理不同的事件,比如删除图像。

任何人都可以帮助我如何附加带有笔记的图像并在EditText中显示它们吗?

1 个答案:

答案 0 :(得分:1)

我终于得到了这个问题的解决方案,现在我的代码在我的Android应用程序中完全正常工作。

这是我用来在Android中的EditText中添加/绘制图像然后在它们上面读取触摸事件的代码。

Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.ic_document);
final Drawable d = new BitmapDrawable(getResources(), b);
d.setBounds(0, 0, 200, 200);
final ImageSpan is = new ImageSpan(d);

SpannableStringBuilder ss = new SpannableStringBuilder(".\n");
ss.setSpan(is, 0, (".\n").length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new MyClickAbleSpan("abc"), 0, (".\n").length(), 0);
editor.append(ss, 0, (".\n").length());
editor.setMovementMethod(LinkMovementMethod.getInstance());

这是MyClickAbleSpan类: -

class MyClickAbleSpan extends ClickableSpan {

    String filePath;

    public MyClickAbleSpan(String filePath) {
        this.filePath = filePath;
    }

    @Override
    public void onClick(View widget) {
        Toast.makeText(SpannableActivity.this, filePath, Toast.LENGTH_LONG).show();

    }
}
相关问题