单击外部后

时间:2019-12-11 11:32:38

标签: android android-webview

我创建了一个网页,其中放置了一个text field并将该文本字段用作自动完成。当autocomplete出现时,此focus()加载数据并键入任何值。它可以正常工作并显示autocomplete

当我在Android Web视图中运行此页面时,出现了一些问题。当focus上的text field(在WebView中)并键入value时,它不会加载自动完成值。当我在文本字段click的外部focus再次在文本字段WebView时,它将加载自动完成值。

谁能告诉我autocomplete在第一个focus之后加载的focus所需的哪些设置,而无需定义第二个public class ShowDetailsActivity extends AppCompatActivity { private String myUrl="url"; public WebView webView=null; SharedPreferences sharedPreferences; GPSTracker tracker=null; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_show_details); webView = (WebView) findViewById(R.id.ftnxtWebView); sharedPreferences = getSharedPreferences(Constants.SHARED_PREF_LOGIN, Context.MODE_PRIVATE); final String android_id = Secure.getString(getContentResolver(), Secure.ANDROID_ID); Log.d("Android ID: ",""+android_id); if (!CommonLogic.checkPermission(getApplicationContext())) { Log.i("Permission Check", "Permission not granted."); CommonLogic.showPermissionDialog(ShowDetailsActivity.this); } tracker = new GPSTracker(ShowDetailsActivity.this); if(tracker.canGetLocation()){ double latitude = tracker.getLatitude(); double longitude = tracker.getLongitude(); String location = latitude+","+longitude; /* SharedPreferences.Editor ed= sharedPreferences.edit(); ed.putString(Constants.SHARED_PREF_LOCATION,location); ed.commit();*/ }else{ // can't get location // GPS or Network is not enabled // Ask user to enable GPS/network in settings tracker.showSettingsAlert(); } webView.requestFocus(View.FOCUS_DOWN|View.FOCUS_UP); webView.getSettings().setLightTouchEnabled(true); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setPluginState(WebSettings.PluginState.ON); webView.getSettings().setSupportZoom(true); webView.getSettings().setBuiltInZoomControls(true); webView.getSettings().setAllowFileAccess(true); webView.getSettings().setAllowContentAccess(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); webView.getSettings().setDisplayZoomControls(true); webView.getSettings().setSaveFormData(true); webView.getSettings().setUseWideViewPort(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); webView.getSettings().setSupportMultipleWindows(true); webView.getSettings().setAllowUniversalAccessFromFileURLs(true); webView.getSettings().setDefaultTextEncodingName("utf-8"); webView.getSettings().setGeolocationEnabled(true); webView.getSettings().setGeolocationDatabasePath(getFilesDir().getPath()); webView.setWebChromeClient(new WebChromeClient() { @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); } }); webView.addJavascriptInterface(new WebAppInterface(this), Constants.JAVASCRIPT_KEY); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); webView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } @Override public void onUnhandledKeyEvent(WebView view, KeyEvent event) { return; } public InputConnection onCreateInputConnection(EditorInfo outAttrs) { return new BaseInputConnection(webView, false); //this is needed for #dispatchKeyEvent() to be notified. } @Override public void onPageFinished(WebView view, String url) { if(sharedPreferences != null) { String userID= sharedPreferences.getString(Constants.USER_NAME,""); String password=sharedPreferences.getString(Constants.USER_PASSWORD,""); String location = sharedPreferences.getString(Constants.SHARED_PREF_LOCATION,"");; Log.d("UserName----",userID); Log.d("UserPass----",password); Log.d("UserLocation----",location); webView.loadUrl("javascript:(function(){document.getElementsByName('username')[0].value='" + userID + "';document.getElementsByName('password')[0].value='" + password+ "';document.getElementsByName('userLocation')[0].value='" + location+"'})()"); } super.onPageFinished(view, url); } }); /*HashMap<String, String> headerMap = new HashMap<>(); headerMap.put("app_type","app"); headerMap.put("device_id",android_id);*/ InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0); webView.loadUrl(myUrl); } /*@Override public void onBackPressed() { if (webView.canGoBack()) { webView.goBack(); } else { super.onBackPressed(); } }*/ // this is from the Android Docs public class WebAppInterface { Context mContext; /** Instantiate the interface and set the context */ WebAppInterface(Context c) { mContext = c; } /** Show a toast from the web page */ @JavascriptInterface public void showFields(String username, String password) { //Toast.makeText(mContext, email+" "+name , Toast.LENGTH_SHORT).show(); //System.out.println("Email " + email + "Name - "+name); SharedPreferences.Editor ed= sharedPreferences.edit(); ed.putString(Constants.USER_NAME,username); ed.putString(Constants.USER_PASSWORD,password); ed.commit(); Log.d("Message-----","Sharedprerefence saved"); } @JavascriptInterface public String setLocationInWeb(){ String location=""; GPSTracker trackerWeb = new GPSTracker(ShowDetailsActivity.this); if(trackerWeb.canGetLocation()) { double latitude = trackerWeb.getLatitude(); double longitude = trackerWeb.getLongitude(); location = latitude + "," + longitude; } /*Toast.makeText(getApplicationContext(), "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();*/ return location; } } /*@Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { return new BaseInputConnection(webView, false); //this is needed for #dispatchKeyEvent() to be notified. }*/ @Override public boolean dispatchKeyEvent(KeyEvent event) { boolean dispatchFirst = super.dispatchKeyEvent(event); // Listening here for whatever key events you need if (event.getAction() == KeyEvent.ACTION_UP) switch (event.getKeyCode()) { case KeyEvent.KEYCODE_SPACE: case KeyEvent.KEYCODE_ENTER: // e.g. get space and enter events here break; } return dispatchFirst; } }

create table lookup (
 lookupId int identity primary key, 
 userName nvarchar(100),
 createdOn datetime2 not null
 default sysdatetime()
)
GO

这是我在webview中运行网页的代码。

0 个答案:

没有答案