Thursday, November 4, 2010

Android ScrollView workaround fun

There are lots of little things that can be rather...headache worthy. ScrollView is a great little widget that with one simple entry, you get scrolling. However, depending on what you put in it, can lead to some interesting results. For instance, don't stick things like Lists in it. In my case, it was a simple EditText box that caused some issues.

Upon launch, EditText grabbed the focus causing the virtual keyboard to come up. This was due to having no available focuses, it chose my EditText box. Digging into it, the obvious solution that has many posts android:focusable="false" and the android:focusableInTouchMode="false". Of course, that doesn't help if you really want to focus on it.

The end result was to set these to false and upon click, change the modes. All to get around the issue with focus firing on this text box. Something like:

public OnTouchListener mNotesTouchListener = new OnTouchListener() {

public boolean onTouch(View arg0, MotionEvent arg1) {
return false;

And the good thing is none of it affects using the trackball and DPad. Granted this seems like a minor issue. At least it can be worked around.