views:

871

answers:

4

Hi all.

I'm developing an Android application that uses a WebView to display the login page for Facebook. The page loads beautifully, and I'm able to select the username/password textboxes, but typing in them will not work. That is, they definitely have input focus (they have the orange focus highlight box and a flashing cursor), but typing in them does absolutely nothing. I'm not certain, but I think maybe the form buttons are also playing up - they appear to be simply refreshing the page, rather than submitting the form.

Just to be clear, although I'm particularly interested in getting Facebook running, I'm sure that this isn't a Facebook issue since other websites (Google, etc) also display the same behaviour.

Does anyone have any ideas what might be the issue?

Thanks!

Mac.

A: 

Not sure if it's the problem since other websites also display the same behavior, but have you enabled javascript? A WebView does not enable it by default.

WebView webView = (WebView)findViewById(R.id.yourWebView);
webView.getSettings().setJavaScriptEnabled(true);
wf
Yes, I have enabled JavaScript. I don't imagine that should be the issue either, since AFAIK the forms don't rely on JS for the basic input. I've also tried using the Facebook WAP login site (which definately doesn't use JS) with the same results. Thanks though.
Mac
+10  A: 

Turns out that it was apparently the WebView not having focus that was the issue.

I discovered that using the arrow keys to get focus on the textboxes caused them to work, so I theorised that there was an issue somewhere with something not having focus, most likely the WebView not having focus. Sure enough, adding the following line seemed to fix the problem:

webView.requestFocus(View.FOCUS_DOWN);

I'm still at a loss to explain exactly why the issue occurred in the first place - the textboxes should work whether they receive focus from being tapped upon or through being "arrowed" to - but at least I have a solution that appears to work.

Thanks for your input wf.

Mac
Thanks for posting this answer -- it helped me out.
twk
A: 

I encountered this problem because I am displaying a splash image while the webview is loading the first page. I am setting the webview to View.VISIBLE in onPageFinished, however despite being able to focus text boxes you can't type into them. I too can confirm that the fix to set the webview requestFocus to View.FOCUS_DOWN works.

NB. If I set the webview to View.VISIBLE in onResume the problem does not present itself but in my case the splash image disapears too soon.

jhad
A: 

@Mac Does this single line :

webView.requestFocus(View.FOCUS_DOWN);

solved your problem ? I didn't in my case ,but this does :

mWebView.setOnTouchListener(new View.OnTouchListener() { 
@Override
public boolean onTouch(View v, MotionEvent event) {
           switch (event.getAction()) { 
               case MotionEvent.ACTION_DOWN: 
               case MotionEvent.ACTION_UP: 
                   if (!v.hasFocus()) { 
                       v.requestFocus(); 
                   } 
                   break; 
           } 
           return false; 
        }
});

just for your referrence.

DiveInto