-1

I'm new to Android programming. What I'm trying to do is get a image from the gallery or take it from the camera, and insert into the edittext which might have texts on it. (e.g., text....text...text.. [IMAGE])

How should the code for getting a image and insert it into the selected cursor point of the edittext?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

2 Answers2

1

You can do this with 2 methods

1)With SpannableString

 SpannableString ss = new SpannableString("abc\n");
    Drawable d = img.getDrawable();
    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);
    editText.setText(ss);

2) With CompoundDrawablesWithIntrinsicBounds

editText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.image, 0, 0, 0);
Amarjit
  • 4,327
  • 2
  • 34
  • 51
1

Try this to do programmatically:

EditText et_EditImage = (EditText)findViewById(R.id.et_EditImage);
et_EditImage.setCompoundDrawables(null, null, getResources().getDrawable(R.drawable.tick), null);

Try this to do it in XML file:

<FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <EditText
                android:id="@+id/search"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/search_bar"
                android:drawablePadding="8dp"
                android:paddingLeft="30dp"
                android:paddingRight="10dp"
                android:singleLine="true" >
                <requestFocus />
            </EditText>

            <Button
                android:id="@+id/searchBtn"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:layout_margin="10dp"
                android:background="@drawable/icon_magnify" />

            <Button
                android:id="@+id/delete"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center_vertical"
                android:layout_margin="8dp"
                android:background="@drawable/icon_remove" />
        </FrameLayout>

I found that on Here

Community
  • 1
  • 1
Aspicas
  • 4,498
  • 4
  • 30
  • 53