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

  • Home
  • SEARCH
  • 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 6002559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:59:44+00:00 2026-05-23T00:59:44+00:00

I am an android and iphone developer. I am a newbie though working on

  • 0

I am an android and iphone developer. I am a newbie though working on this huge project. I am trying to implement the leftView, leftviewmode,rightview,rightviewmode properties of the textfield in iphone in android.

I was thinking that with the leftview and rightview the setCompoundDrawables() method could meet the challenge. However, I am stumped as to how to implement the various modes; “Never”, “always” etc.

Am I on the right track? Could anyone please help?

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-05-23T00:59:45+00:00Added an answer on May 23, 2026 at 12:59 am

    This code will give you an Android EditText field that functions exactly like an iPhone UITextField with options for clearbuttonmode, leftview, rightview, leftviewmode, rightviewmode, UITextFieldViewModeNever, UITextFieldViewModeWhileEditing, UITextFieldViewModeUnlessEditing, UITextFieldViewModeAlways

        String value = "";//any text you are pre-filling in the EditText
        final String viewMode = "editing";//never | editing | unlessEditing | always
        final String viewSide = "right"; //left | right
        final EditText et = new EditText(this);
        et.setText(value);
        //your leftview, rightview or clearbuttonmode image. for clearbuttonmode this one from standard android images looks pretty good actually
        final Drawable x = getResources().getDrawable(R.drawable.presence_offline);
        x.setBounds(0, 0, x.getIntrinsicWidth(), x.getIntrinsicHeight());
        Drawable x2 = viewMode.equals("never")?null:viewMode.equals("always")?x:viewMode.equals("editing")?(value.equals("") ? null : x):viewMode.equals("unlessEditing")?(value.equals("") ? x : null):null;
        et.setCompoundDrawables(viewSide.equals("left")?x2:null, null, viewSide.equals("right")?x2:null, null);
        et.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (et.getCompoundDrawables()[viewSide.equals("left")?0:2] == null) {
                    return false;
                }
                if (event.getAction() != MotionEvent.ACTION_UP) {
                    return false;
                }
                //x pressed
                if ((viewSide.equals("left")&&event.getX() < et.getPaddingLeft() + x.getIntrinsicWidth())
                        ||(viewSide.equals("right")&&event.getX() > et.getWidth() - et.getPaddingRight() - x.getIntrinsicWidth())) {
                    Drawable x3 = viewMode.equals("never")?null:viewMode.equals("always")?x:viewMode.equals("editing")?null:viewMode.equals("unlessEditing")?x:null;
                    et.setText("");
                    et.setCompoundDrawables(viewSide.equals("left")?x3:null, null, viewSide.equals("right")?x3:null, null);
                }          
                return false;
            }
        });
        et.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                Drawable x4 = viewMode.equals("never")?null:viewMode.equals("always")?x:viewMode.equals("editing")?(et.getText().toString().equals("") ? null : x):viewMode.equals("unlessEditing")?(et.getText().toString().equals("") ? x : null):null;
               et.setCompoundDrawables(viewSide.equals("left")?x4:null, null, viewSide.equals("right")?x4:null, null);
            }
    
            @Override
            public void afterTextChanged(Editable arg0) {
            }
    
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am iPhone application developer, many people told me to join with the android
I am working an XMPP client for both Android and iPhone. I have been
I've been working on the Android SDK platform, and it is a little unclear
I am an iphone application developer, all iphones have very similar Operating systems, and
I consider myself an Android developer, after having created four apps and learned a
On a touch device like iPhone/iPad/Android it can be difficult to hit a small
I am trying to build an Android Soft keyboard application using avail code at
I've developed several iPhone apps and now I'm porting them onto Android. From what
I want to develop an application targeting both android and iphone. I guess they
I'm currently deciding what way to build my Iphone/Android app. I just need to

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.