Android starts the Activity and prevents EditText from Automatically Obtaining the focus. androidedittext

Source: Internet
Author: User

Android starts the Activity and prevents EditText from Automatically Obtaining the focus. androidedittext

This problem is a hot issue in StackOverFlow. Stop EditText from gaining focus at Activity startup. Now I will translate this question and sort out the answers to ensure that this problem can be solved.

The author encountered the following problems:

I have an Activity with an EditText and a ListView. When I start the Activity, EditText automatically obtains the focus (the cursor is flashing ). But I don't want him to get the focus. I tried the following statement:

EditText. setSelected (false );

But it does not work at all. How can I prevent EditText from getting the focus itself?

Summary:

Answer 1: Make sure that the requestFocus label is not found in your xml layout file. This label will be automatically added by eclipse. If so, delete it.

Answer 2: Add two rows in the parent layout of EditText.

<LinearLayout android: focusable = "true" android: focusableInTouchMode = "true"/>

In this way, the parent layout gets the focus by default, and the focus is snatched from EditText.

Answer 3: No Answer 3. The above two answers can basically solve the problem.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.