Bug 21373 - [Android only] An Entry in a ViewCell loses focus immediately
Summary: [Android only] An Entry in a ViewCell loses focus immediately
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.1
Hardware: PC Mac OS
: Normal normal
Target Milestone: 1.3.5
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-07-16 13:04 UTC by John Miller [MSFT]
Modified: 2015-02-19 17:32 UTC (History)
10 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
TestCase (2.80 MB, application/zip)
2014-07-16 13:04 UTC, John Miller [MSFT]
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description John Miller [MSFT] 2014-07-16 13:04:25 UTC
Created attachment 7392 [details]
TestCase

### Overview: 

    A TableView contains a ViewCell which sets its View as an Entry. This entry will loose focus immediately when touched, preventing the user from entering text into it. Here is a screencast of the issue in action: http://screencast.com/t/m1oaOonJ

### Steps to Reproduce: 

    1. Run the attached sample project
    2. Touch on the first Entry, it will loose focus immediately. Touching again will gain focus. 
    3. Touch the entry in the second section, it will not gain focus. 

### Actual Results: 

    Unable to get the entry to focus.

### Expected Results: 

    Entry should gain focus consistently. 

### Build Date & Platform: 

    XF 1.2.1

### Additional Information: 

    Using an EntryCell instead of a ViewCell -> Entry works as expected.
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2014-09-15 03:03:58 UTC
## Workaround

Add the following attribute to the MainActivity in the Android application project:
WindowSoftInputMode = global::Android.Views.SoftInput.AdjustPan


This problem also affects native EditText widgets within native ListViews in Java apps on Android.
(See for example [1, 2])
> [1] http://stackoverflow.com/questions/9272140/edittext-in-listview-android
> [2] http://androidtechnicalblog.blogspot.com/2014/04/quick-trick-of-week-edittext-inside.html


## Result on iPhone, Windows Phone Emulator

The Entry view behaves as desired: it gains focus consistently and retains focus during subsequent key presses.


## Closely related bugs
"Android - ViewCell - Entry and non default Keyboard type"
https://bugzilla.xamarin.com/show_bug.cgi?id=20786

"[Android only, certain soft keyboards] EntryCell loses focus while typing"
https://bugzilla.xamarin.com/show_bug.cgi?id=22984


## New knowledge base article
"[Android] EntryCells and Entry views within ViewCells lose focus"
http://kb.xamarin.com/customer/portal/articles/1690276
Comment 2 Jason Smith [MSFT] 2015-02-13 15:40:49 UTC
Should be fixed in 1.3.5-pre1
Comment 3 Ram Chandra 2015-02-18 05:07:29 UTC
I have checked this issue with following builds:

Xamarin.Forms: 1.3.5.6333-pre1
Mac OS X 10.10.0
Xamarin Studio: 5.7.1 (build 17)
Mono 3.12.0 ((detached/a813491)
GTK+ 2.24.23 (Raleigh theme)
Package version: 312000068
Xcode 6.1 (6604)
Build 6A1052d
Xamarin.iOS : 8.6.2.19 (Business Edition)
Xamarin.Android: 4.20.0.28 (Business Edition)
=== Build Information ===
Release ID: 507010017
Git revision: 0bc7d3550b6b088ac25b08dcf7bbe73bcc8658b3
Build date: 2015-02-03 19:43:29-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

Observation: After updating X.Forms to  X.Forms: 1.3.5.6333-pre1, I observed that Entry control is focused properly and I am able to enter text on it.

Screencast: http://www.screencast.com/t/89jdGm9uhh

This issue has been fixed. Hence I am closing this issue.
Comment 4 Alessandro 2015-02-19 17:20:01 UTC
I'm using 1.3.5.6333-pre1 but I have the same problem of lost focus.
I have an entry with a renderer
	public class MyControlEntryNumericRenderer: EntryRenderer
	{
		protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
		{
			base.OnElementChanged(e);

			if (Control != null) { 
				//Control.ImeOptions =  global::Android.Views.InputMethods.ImeAction.Done//.Next;
				Control.InputType = 
					global::Android.Text.InputTypes.TextFlagNoSuggestions |
					global::Android.Text.InputTypes.ClassNumber;
				Control.SetSelectAllOnFocus (true);
			}
		}
	}

I have a viewcell with a labelNome.IsVisible = true and  entryPrezzo.IsVisible = false (entryPrezzo is MyControlEntryNumericRenderer) .
The label has a 
				tapGestureRecognizer.Tapped += (s, e) => {
					if(s.Equals(labelNome)) {
						editPrezzo.IsVisible = true;
						labelNome.IsVisible = false;
						editPrezzo.Focus();
					}

				};
when I tap on labelNome, entryPrezzo appears: often the focus is lost and a text keyboard appears. Sometimes the focus remain and a correct numeric keyboard appears. Never, the SetSelectAllOnFocus is applyed.

I hope to be clear
Thanks
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2015-02-19 17:32:00 UTC
@Alessandro, thanks for the report. Since the precise issue for this bug report is now VERIFIED FIXED based on the test case in comment 0, the best way to get the issue you're seeing addressed would be to file it on its own bug report, ideally including a complete self-contained, zipped-up test project that demonstrates the issue.

See also https://bugzilla.xamarin.com/page.cgi?id=bug-writing.html for other good instructions about information to include on the bug report.

Thanks!