Note that there are some explanatory texts on larger screens.

plurals
  1. POEdittext onFocusChangeListener is called when unwanted
    text
    copied!<p>I'm currently trying to provide a intuitive interface for my application.</p> <p>I have an oncreate function to activate the keyboard on load which works fine.</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.add_popup); reminder = (CheckBox)findViewById(R.id.reminder_option); addTask(); taskField = (EditText)findViewById(R.id.task_name); taskField.setHorizontallyScrolling(true); taskField.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean focus) { if (focus) { getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); taskField.requestFocus(); </code></pre> <p>When the checkbox is clicked, the keyboard is dismissed</p> <pre><code>if(checked){ imm.hideSoftInputFromWindow(taskField.getWindowToken(), 2); dateTitle.setVisibility(View.VISIBLE); dateSelector.setVisibility(View.VISIBLE); timeTitle.setVisibility(View.VISIBLE); timeSelector.setVisibility(View.VISIBLE); datetimesperator.setVisibility(View.VISIBLE); </code></pre> <p>I am using 2 inner classes, a TimePickerFragment and a DatePickerFragment both implementing the onDate/TimesetListener.</p> <p>Now the problem is that when a time or date is set from the popups, the keyboard is reactivated.</p> <p>I attempted a solution from <a href="https://stackoverflow.com/questions/1555109/stop-edittext-from-gaining-focus-at-activity-startup/1612017#1612017">Stop EditText from gaining focus at Activity startup</a></p> <p>Where the layout is set focusable to remove focus from the edittext, I added the following code to the if checked statement. RelativeLayout layout = (RelativeLayout)findViewById(R.id.add_container); layout.requestFocus();</p> <p>However after setting either the date or time, in the respective dialogs, the keyboard is still activated despite the focus being moved away from the edittext element.</p> <p>How can I prevent the keyboard from being activated when exiting the DatePickerDialog or the TimePickerDialog?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload