如何使用Webview?

时间:2016-04-21 05:34:02

标签: android webview

  String  fbid = getIntent().getStringExtra("id");//Getting this value from previous screen

     Log.e( "What I am getting : " + fbid);


    final String url = "https://www.fbbexample.com/abc/"+fbid;  //**not working**

Log.e( "url I am getting : " + url); Log value:  https://www.fbbexample.com/abc/59



// final String url2 = "https://www.fbbexample.com/abc/"+59;  //**this is working**

   //  Log.e( "url2 I am getting : " + url2);  Log value:  https://www.fbbexampl.com/abc/59

    webView = (WebView) findViewById(R.id.webView);       



    webView.getSettings().setJavaScriptEnabled(true);

    webView.loadUrl(url);

    webView.getSettings().setBuiltInZoomControls(true);

    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            // webView.getSettings().setBuiltInZoomControls(true);
            return true;
        }
    });
}
}

我所面对的是当我硬编码字符串“fbid”时它起作用,当我按照上面提到的那样尝试它然后得到空白屏幕...... ....

Intent intent = new Intent(getContext(),SingleFbb.class);
                       intent.putExtra( “ID”,IDNO);

2 个答案:

答案 0 :(得分:0)

试试这个。这将删除空格,

String  fbid = getIntent().getStringExtra("idmindmaps");

你也使用错误的密钥从透过屏幕获取价值。 你的代码中的正确密钥是“idmindmaps”,所以请使用它。

varSide = 0
document.getElementById("demo").innerHTML = varSide; 

function myFunctionLeft(id1,id2,id3,id4) {
    var a = document.getElementById(id1);
    var b = document.getElementById(id2);
    var c = document.getElementById(id3);
    var d = document.getElementById(id4);

        if (varSide==0){
        varSide = -1;
        a.style.display = 'block';
        b.style.display = 'none';
        c.style.display = 'none';
        d.style.display = 'none';
    }
    else if (varSide==-1){
        varSide = 2;
        a.style.display = 'none';
        b.style.display = 'none';
        c.style.display = 'none';
        d.style.display = 'block';
    }
    else if (varSide==2){
        varSide = 1;
        a.style.display = 'none';
        b.style.display = 'none';
        c.style.display = 'block';
        d.style.display = 'none';
    }
    else{
        varSide = 0;
        a.style.display = 'none';
        b.style.display = 'block';
        c.style.display = 'none';
        d.style.display = 'none';
    }
    document.getElementById("demo").innerHTML = varSide; 
}   

function myFunctionRight(id1,id2,id3,id4) {
    var a = document.getElementById(id1);
    var b = document.getElementById(id2);
    var c = document.getElementById(id3);
    var d = document.getElementById(id4);

        if (varSide==0){
        varSide = 1;
        a.style.display = 'none';
        b.style.display = 'none';
        c.style.display = 'block';
        d.style.display = 'none';
    }
    else if (varSide==1){
        varSide = 2;
        a.style.display = 'none';
        b.style.display = 'none';
        c.style.display = 'none';
        d.style.display = 'block';
    }
    else if (varSide==2){
        varSide = -1;
        a.style.display = 'block';
        b.style.display = 'none';
        c.style.display = 'none';
        d.style.display = 'none';
    }
    else{
        varSide = 0;
        a.style.display = 'none';
        b.style.display = 'block';
        c.style.display = 'none';
        d.style.display = 'none';
    }

    document.getElementById("demo").innerHTML = varSide; 
    }

答案 1 :(得分:0)

试试这个

      public class ShowSubjectListItemsInWebView extends ActionBarActivity {
        private WebView webView;       

        private ProgressDialog dialog;
        private String url;


        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_show_subject_list_items_in_web_view);
            this.initViews();
            String  fbid = getIntent().getStringExtra("idmindmaps");
            url= "https://www.fbbexample.com/abc/"+fbid; 
            loadWebView(url);
        }

        //initializes all views
        private void initViews() {
            webView = (WebView) findViewById(R.id.filesWebView);
        }

        //show Url in WebView
        public class myWebClient extends WebViewClient {
            @JavascriptInterface
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);
                dialog = new ProgressDialog(ShowSubjectListItemsInWebView.this);
                dialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
                dialog.setCancelable(false);
                dialog.setMessage(Constant.KEY_PLEASE_WAIT);
                dialog.show();
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
            }
        }

        public void loadWebView(String url) {
            webView.setWebViewClient(new myWebClient());
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setBuiltInZoomControls(true);
            webView.getSettings().setUseWideViewPort(true);
            webView.getSettings().setLoadWithOverviewMode(true);
            webView.getSettings().setDomStorageEnabled(true);
            webView.setVisibility(View.VISIBLE);
            webView.loadUrl(url);
        }

   }