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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:45:42+00:00 2026-06-02T02:45:42+00:00

I want to create 1 edit text with the below condition: – User can

  • 0

I want to create 1 edit text with the below condition:
– User can not focus on this control in normal.
– When user click on this control, soft-keyborad is displayed and user can input into this control
– When user press enter on this soft-keyborad or back on device, it is closed and back to normal view with control is not focus.

I tried the below code but not work 🙁
When starting, control is not focus: ok

When click on control, at the first click, control is focus but not display soft-keyborad

In the second click, display soft-keyborad

  • When press enter button in soft-keyborad: back to screen with control is not focus: OK
  • When press back button device, back to screen with control is still focus : not ok

    public void onCreate(Bundle savedInstanceState)
    {
    final EditText txtSearch = (EditText)this.findViewById(R.id.p60004_txt_search_str);
    txtSearch.setOnClickListener(new OnClickListener() {
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            txtSearch.setFocusable(true);//(false);
            txtSearch.setFocusableInTouchMode(true);
            txtSearch.requestFocus();
        }
    });
    txtSearch.setOnKeyListener(new OnKeyListener() {
    
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
                    (keyCode == KeyEvent.KEYCODE_ENTER))
                {
                    String strSearch = txtSearch.getText().toString();
                    if (strSearch != null && strSearch != ""){
                            searchFriend(UserAPIConstants.FRIEND_SEARCH_TYPE_SC, strSearch);
                    }
    
                    hideSoftKeyboard(v);
                    txtSearch.setFocusable(false);
                    txtSearch.setFocusableInTouchMode(false);
    
                }
    
            return false;
        }
    });
    public void hideSoftKeyboard (View view) {
      InputMethodManager imm = (InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }
    
  • 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-02T02:45:45+00:00Added an answer on June 2, 2026 at 2:45 am
    1. In your xml which has edittext put these values for the layout node

       android:focusable="true" 
      android:focusableInTouchMode="true"
      

      and dont put any focusable or focusable in touch mode attributes for your edittext..

    2. Then in your code in onKey method remove thse lines..

       txtSearch.setFocusable(false);
         txtSearch.setFocusableInTouchMode(false);
      

      and put

       txtSearch.clearFocus();
      
    3. And You should override this method

      onBackPressed() 
      

      like this..

       @Override
        public void onBackPressed() {
       txtSearch.clearFocus();
       //hide the soft keyboard..
      
        }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add an edit text field to my app when i click
I want create module which update list of usb devices automatically (not only mass
I want to create a frame and fill it with a segmented control. How
I want to create conditional comments in XSLT. But when I use this: <!--
EDIT ~ I have answered my own question below in the EDIT section, not
I want to create a layout in such a way that on top edittext
I want create a excel with Apache POI in java and I must insert
i want create image animation , i have 50 images with png format now
We want to create a widget platform for a particular website. I couldn't find
I want to create a file in the current directory (where the executable is

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.