Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Android: Prevent automatic scroll to TextField after button click?

$
0
0

In Android code, I have a ScrollView with a TextField at the top, followed by some content and controls such as pickers and switches. After clicking on any of the controls, the ScrollView immediately scrolls to focus the TextField. Is there any way to prevent this? Please see the sample code below. Scroll down to the bottom, click the switch, and watch the window race back up. This is reproducible on SDK 3.2.2.GA as well as 3.3.0, and identical behavior on Android 2.3.6 and Jelly Bean.

var win = Ti.UI.createWindow({
    windowSoftInputMode: Ti.UI.Android.SOFT_INPUT_STATE_ALWAYS_HIDDEN,
    backgroundColor: 'black'});
 
var scrollview = Ti.UI.createScrollView({
    top:'0dp',
    scrollType: 'vertical',
    width: Ti.UI.FILL,
    contentHeight: 'auto',
    contentWidth: 'auto',
    layout: 'vertical',
    showVerticalScrollIndicator: true,
    scrollingEnabled: true});
 
var textfield = Ti.UI.createTextField({top: 10, right: 10, left: 10});
scrollview.add(textfield);
var view = Ti.UI.createView({
    backgroundColor: 'red',
    width: Ti.UI.FILL,
    height: '1000dp',
    top: '100dp'
});
scrollview.add(view);
var Switch = Ti.UI.createSwitch({
    top: '20dp'
});
scrollview.add(Switch);
win.add(scrollview);    
win.open();

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>