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 8804355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:34:56+00:00 2026-06-14T01:34:56+00:00

I have placed a button in EditText, I have set the button invisible at

  • 0

I have placed a button in EditText, I have set the button invisible at starting code of main XML is:

RelativeLayout android:layout_width="match_parent"
    android:layout_height="wrap_content" android:layout_marginTop="10dp">

    <EditText android:id="@+id/editText1" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:hint="@string/search_prompt"/>

    <Button android:id="@+id/button1" android:layout_width="40dp"
        android:layout_height="wrap_content" android:layout_alignBottom="@+id/editText1"
        android:layout_alignParentRight="true" android:layout_alignParentTop="true"
        android:layout_margin="5dp" android:background="@drawable/search"
        android:onClick="loadWeather" android:visibility="invisible"/>

</RelativeLayout>

Now I want that the Button only be visible if there is some text in EditText if EditText is empty the Button should not be visible a have set a setKeyListener listener on EditText in following way:::

final Button searchButton = (Button) findViewById(R.id.button1);

    final EditText myEditText = (EditText) findViewById(R.id.editText1);
    myEditText.setKeyListener(new KeyListener() {

        public boolean onKeyUp(View arg0, Editable arg1, int arg2, KeyEvent arg3) {
            // TODO Auto-generated method stub
            if(!myEditText.getText().equals("")){
                searchButton.setVisibility(View.VISIBLE);
            }
            return false;
        }

        public boolean onKeyOther(View arg0, Editable arg1, KeyEvent arg2) {
            // TODO Auto-generated method stub
            return false;
        }

        public boolean onKeyDown(View arg0, Editable arg1, int arg2, KeyEvent arg3) {
            // TODO Auto-generated method stub
            return false;
        }

        public int getInputType() {
            // TODO Auto-generated method stub
            return 0;
        }

        public void clearMetaKeyState(View arg0, Editable arg1, int arg2) {
            // TODO Auto-generated method stub

        }
    });

It makes Button invisible at starting, but now I’m no more able to enter any text in EditText, EditText does not get any input through keyboard. Please tell mo how to get rid of this bug.

  • 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-14T01:34:57+00:00Added an answer on June 14, 2026 at 1:34 am

    Use instead

    myEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int start, int count,      int after) {
    
        }
    
        @Override
        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
            if( count == 0){
                searchButton.setVisibility(View.INVISIBLE);
            }  else{
                searchButton.setVisibility(View.VISIBLE); 
            }
        }
    
        @Override
        public void afterTextChanged(Editable editable) {
            Log.v(TAG, "afterTextChanged");
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have placed an Image as a button in my App and I want
I have an animated gif placed on the button. It's animating ok (most of
I'm trying to place a button. I have its position set to absolute, so
In my code I have one textbox and one button. Whatever place you type
I am working on a WordPress site and I have placed the following code
I have placed a pause button in UI, where when the user clicks the
In a php page I have placed a submit button, HTML: <input type=submit name=btnAdd
I have created a scrollview, and some button are placed on this scrollview. And
I want to place an image button inside of EditText, but I don't have
I have placed three buttons over UITableViewCell and its background is set to an

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.