Reputation: 384
I have an EditText field where a user enters an inventory location. If the location isn't valid, the error description appears (i.e. "Location not found"), after which the user must press the field again to try another location.
I'm trying to use RequestFocus() so that the user doesn't need to press again before entering another location. It appears to work. The EditText field becomes underlined and the cursor blinks at its beginning, but nothing can be typed. It's as if the field is disabled, but debug shows it both enabled and HasFocus. It is, in fact, the only EditText enabled.
<EditText
p1:layout_width="150dp"
p1:layout_height="33dp"
p1:layout_below="@id/spnrAreas"
p1:id="@+id/etxtLocation"
p1:layout_toRightOf="@id/lblLocation"
p1:textColor="@color/Black"
p1:inputType="textCapCharacters"
p1:nextFocusDown="@+id/etxtItem" />
{txtErrorMessage.Text = "Location not found";
etxtLocation.Text = "";
etxtLocation.RequestFocus();
return; }
Is there a method other than RequestFocus() that would make the program behave as if the EditText (etxtLocation) were pressed?
Upvotes: 1
Views: 172
Reputation: 384
I was able to resolve this by moving the "etxtLocation.RequestFocus()" into the "extItem" FocusChange() event handler, where focus shifted to after pressing enter. From there it behaves as intended:
void etxtItem_FocusChange(object sender, View.FocusChangeEventArgs e)
{
if (etxtItem.HasFocus)
{
//request focus back to Location if its value was incorrect.
if (String.IsNullOrEmpty(etxtLocation.Text))
{
etxtLocation.RequestFocus();
} } } return;
Upvotes: 0
Reputation: 21
Try this:
etxtLocation.RequestFocus();
InputMethodManager imm = (InputMethodManager) GetSystemService(Context.InputMethodService);
imm.ShowSoftInput(etxtLocation, ShowFlags.Implicit);
Upvotes: 2