使用html链接位置的Webview只能点击一次超链接

时间:2012-01-10 02:00:58

标签: android html webview

我似乎是这样,当我在Android webview上使用我的链接位置时,它只允许我点击一次。然后,当我再次点击它时,它不会引导我到已经链接的地方。但是,当我使用2个按钮,然后交替点击它们时,它会以这种方式工作,但我需要知道如何只使用1个按钮并链接它,并能够继续使用它。下面是我对html以及webview的编码。

    public class more extends Activity{
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            getAssets();
            WebView web = new WebView(this);
            web.getSettings().setJavaScriptEnabled(true);
            web.loadUrl("file:///android_asset/more123.html");
            setContentView(web);


    }

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
            if ((keyCode == KeyEvent.KEYCODE_BACK)) {
                Log.d(this.getClass().getName(), "back button pressed");
                finish();
            }
            return super.onKeyDown(keyCode, event);
        }


    }


    <html>
    <body>

    <p>
    <a href="#C4">See also Chapter 4.</a>
    </p>

    <h2>Chapter 1</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 2</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 3</h2>
    <p>This chapter explains ba bla bla</p>

    <h2><a name="C4">Chapter 4</a></h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 5</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 6</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 7</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 8</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 9</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 10</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 11</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 12</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 13</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 14</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 15</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 16</h2>
    <p>This chapter explains ba bla bla</p>

    <h2>Chapter 17</h2>
    <p>This chapter explains ba bla bla</p>

    </body>
    </html>

2 个答案:

答案 0 :(得分:1)

boolean isClicked=false;
webView.setWebViewClient(new WebViewClient() {

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub

    if(url.equals("ur desired url") && isClicked==false)
    {
    //HYPER LINK IS CLICKED FIRST TIME
    isClicked=true;
                    super.onPageStarted(view, url, favicon);

    }
    else
    {
    //DO NOTHING HYPER LINK IS ALREADY CLICKED

    }



            }
        });

答案 1 :(得分:0)

将此添加到您的代码可能会有所帮助;

private class myWebViewClient extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) 
    {
        view.loadUrl(url);
        return true;
    }
}