Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:52:52+00:00 2026-06-14T12:52:52+00:00

I need to add a touchable image view inside an edit text like ms

  • 0

I need to add a touchable image view inside an edit text like ms word screen.How can we design an android layout screen for this purpose?I have tried the code shown below:

public class edittext extends EditText 
{
     public String defaultValue = "";
        final Drawable imgX = getResources().getDrawable(android.R.drawable.presence_offline ); // X image

    private Html.ImageGetter imageGetter;
    public edittext(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        init();
        // TODO Auto-generated constructor stub
    }
    public edittext(Context context, AttributeSet attrs, int defStyle) 
    {
        super(context, attrs, defStyle);
        init();
        // TODO Auto-generated constructor stub
    }
    public edittext(Context context) 
    {
        super(context);
        init();
        // TODO Auto-generated constructor stub
    }
     void init()  {

            // Set bounds of our X button
            imgX.setBounds(0, 0, imgX.getIntrinsicWidth(), imgX.getIntrinsicHeight());      

            // There may be initial text in the field, so we may need to display the button
            manageClearButton();

           edittext.this.setOnTouchListener(new OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event) {

                    edittext et = edittext.this;

                    // Is there an X showing?
                    if (et.getCompoundDrawables()[2] == null) return false;
                    // Only do this for up touches
                    if (event.getAction() != MotionEvent.ACTION_UP) return false;
                    // Is touch on our clear button?
                    if (event.getX() > et.getWidth() - et.getPaddingRight() - imgX.getIntrinsicWidth()) {
                        et.setText("");
                        edittext.this.removeClearButton();
                    }
                    return false;
                }
            });

            edittext.this.addTextChangedListener(new TextWatcher() {
                public void onTextChanged(CharSequence s, int start, int before, int count) {

                   edittext.this.manageClearButton();
                }

                public void afterTextChanged(Editable arg0) {
                }

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }
            });
        }

        void manageClearButton() {
            if (this.getText().toString().equals("") )
                removeClearButton();
            else
                addClearButton();
        }
        void addClearButton() {
            this.setCompoundDrawables(this.getCompoundDrawables()[0], 
                    this.getCompoundDrawables()[1],
                    imgX,
                    this.getCompoundDrawables()[3]);
        }
        void removeClearButton() {
            this.setCompoundDrawables(this.getCompoundDrawables()[0], 
                    this.getCompoundDrawables()[1],
                    null,
                    this.getCompoundDrawables()[3]);
        }   

}

if anyone knows about it please help me with thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:52:53+00:00Added an answer on June 14, 2026 at 12:52 pm

    I am doing it like that. The Drawable will be at the right side of the EditText. Please try the code.

    EditText contactLine = new EditText(getActivity());
    Drawable drawable =  getActivity().getResources().getDrawable(...);
    drawable.setBounds(new Rect(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()));
    contactLine.setCompoundDrawables(null, null, drawable, null);
    contactLine.setOnTouchListener(new OnTouchListener() {
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Drawable co =  v.getCompoundDrawables()[2];
                if (co == null) {
                    return false;
                }
                if (event.getAction() != MotionEvent.ACTION_DOWN) {
                    return false;
                }
                if (event.getX() > v.getMeasuredWidth() - v.getPaddingRight()
                        - co.getIntrinsicWidth()) {
                    whatYouWantToDo();
                    return true;
                } else {
                    return false;
                }
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't access a element with its href. Like this example, i need add
I need add hint like 'with(index(PK_SomethingObjects))' for optimize my query. How can I add
I'm having trouble in my Android application. I need add LinearLayouts inside another linearlayout.
We need to add a javascript element inside an iframe (its inside the same
I need to add a custom view to a model admin similar to the
I need add to my active main view a new subview. And this subview
I need add in runtime a png image to a TImageList . I've looked
I have small requirement: I need add image over(up) the another image through javascript.
I would like to use CNF in my RCP application, but I need add
How can I call an AutoIt EXE file to Python code? I need add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.