Prevent EditText from automatically gaining focus after Android starts activity

Source: Internet
Author: User

This problem is stackoverflow above a hot issue with Stop EditText from gaining focus at Activity startup. Now I will translate this question and collate the answers to ensure that this problem can be solved.

The author encounters the following problems:

I have an activity with a edittext and a ListView, and whenever I start the activity, EditText automatically gets the focus (where the cursor flashes). And I don't want him to get the focus, I tried the following statement

EditText.setSelected(false);

But it doesn't work at all, how should I stop edittext from getting the focus?

Summary of the answer:

Answer 1: Make sure your XML layout file does not have a requestfocus tag, which will be automatically added by Eclipse, and if so, delete it.

Answer 2: Add two rows to the parent layout where EditText is located

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

This way the parent layout gets the focus by default, and the focus is snatched from the edittext.

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

Prevent EditText from automatically gaining focus after Android starts activity

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.