0

I have an activity where the user is presented with a list of edit texts. The problem is, as soon as the activity starts, the virtual keyboard is brought up right away for the first edit text. I don't want this to happen as there is a spinner before this edit text, and often I've found that popping up the keyboard like this makes the user forget about that previous spinner.

Here's the relevant code:

<Spinner
    android:id="@+id/event_location"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="30px"
    android:prompt="@string/location_prompt" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Event Name: " />
<EditText
    android:id="@+id/event_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Activity Type: " />
<Spinner
    android:id="@+id/event_type"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Address: " />
<EditText
    android:id="@+id/event_address"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Summary: activity with an EditText starts, and the virtual keyboard automatically pops up. I don't want it to do this unless the user presses on the edit text.

Thanks for any help.

3 Answers 3

2

The EditText is automatically set to focus so you need to put android:focusable="false" or editText.setFocusable(false) to prevent the EditText to be focused while the spinner is visible. You could also try editText.setSelected(false).

Sign up to request clarification or add additional context in comments.

Comments

1

Try changing your spinner XML to this:

<Spinner 
android:layout_marginTop="30px"
android:layout_height="wrap_content" 
android:layout_width="fill_parent" 
android:id="@+id/event_location"
android:prompt="@string/location_prompt">
<requestFocus />
</Spinner>

Also try to do for each EditText:

android:focusable="false"
android:focusableInTouchMode="false"

Look at this post: Stop EditText from gaining focus at Activity startup

1 Comment

alright sure, I'll try that out. Is there a way I could just make it so that nothing has a prompt? I.e. nothing "pops up" until the user clicks on something. EDIT - the requestFocus did not change anything.
1

This is how it works for me:

  1. to make sure the edit text wont get focus on startup:
    In xml set the focusable attribute of the EditText to false:
android:focusable="false"

2. in order to make the EditText focusable again after startup:
set the focusable attribute from code in the oncreate() method of the wanted activity after the setContent() method:

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.main_view);
    ....

    EditText et = (EditText) findViewById(R.id.et_notes);

    et.setFocusable(true);

    et.setFocusableInTouchMode(true);

    ...
}  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.