Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8957] Android: hardware keyboard issue with scrollview and testField

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-05-03T18:23:50.000+0000
Affected Version/sRelease 2.1.0, Release 2.0.1
Fix Version/sn/a
ComponentsAndroid
Labelsapi
ReporterRadamantis Torres-Lechuga
AssigneeAllen Yeung
Created2012-05-02T16:23:38.000+0000
Updated2017-03-13T18:33:08.000+0000

Description

Problem

When the user try to use the hardware keyboard, anytime that the user stroke a key, the textfield get's blurred,

Expected behavior

Use the hardware keyboard to introduce text into the text field with no problems

Notes

I'm using a eventlistener to catch anytime the textfield change, if I put a scrollView.scrollToBottom inside the event Listener, the blur event of the textField gets fired, if I comment the scrollToBottom, then, the user can use the hardware keyboard with no problems

Test case

var win = Titanium.UI.createWindow({ backgroundColor:'blue', modal:true, navBarHidden:true});

	var textField = Ti.UI.createTextArea({
			height:60,//hiddenLabel.height,
			left:10,
			right:10,
			autocapitalization:Ti.UI.TEXT_AUTOCAPITALIZATION_SENTENCES,
			top:5,
			isFocused: false
		});
		var scrollView;
		scrollView = Ti.UI.createScrollView({
			left:0,
			top:0,
			right:0,
			contentHeight:'auto',
			backgroundColor: 'green'
		});

		
		textField.addEventListener('focus', function(e)
		{
			Ti.API.info('textField has been focused.');
			textField.isFocused = true;
		});
		textField.addEventListener('blur', function(e)
		{
			Ti.API.info('textField has been blurred.');
			textField.isFocused = false;
		});
		
		textField.addEventListener('change', function(e)
		{
			Ti.API.error('******************************  scrollview to bottom');
			scrollView.scrollToBottom();
			
		});
		
win.add(scrollView);		
win.add(textField);
win.open();

Comments

  1. Allen Yeung 2012-05-03

    This seems to be native behavior in android.
       	private ScrollView sview;
       	
           /** Called when the activity is first created. */
           @Override
           public void onCreate(Bundle savedInstanceState) {
           	super.onCreate(savedInstanceState);
           	RelativeLayout parent = new RelativeLayout(this);
           	sview = new ScrollView(this);
           	MyEditText text = new MyEditText(this);
           	text.setMinimumWidth(200);
       		parent.addView(sview);
       		parent.addView(text);
           	setContentView(parent);
           }
           
          private class MyEditText extends EditText {
       
       	public MyEditText(Context context)
       	{
       		super(context);
       	}
       
       	@Override
       	protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter)
       	{
       		super.onTextChanged(text, start, lengthBefore, lengthAfter);
       		sview.fullScroll(View.FOCUS_DOWN);
       	}
       
    It looks like there is a focus() method on text area, so you may be able to force the textarea to gain focus after it has scrolled to the bottom.
  2. Lee Morris 2017-03-13

    Closing ticket as invalid.

JSON Source