检测android中的位置变化

时间:2012-01-24 18:36:38

标签: android redirect hyperlink webview save

我的Android应用程序包含一个webview。但我有一个问题,因为当我检查网站内的一些复选框并通过网站本身的链接导航到另一个网站,然后返回复选框网站时,复选框将再次取消选中。在默认的android webbrowser中不会发生的事情。我怎样才能解决这个问题???请提前帮助和感谢。我正在使用此代码:

public class finnActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button TilbakeButton;
WebView FinnWeb;
private String currentURL;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    FinnWeb = (WebView)findViewById(R.id.FinnWeb);
    FinnWeb.setWebViewClient(new MyWebViewClient());
    FinnWeb.getSettings().setBuiltInZoomControls(true); 
    FinnWeb.getSettings().setJavaScriptEnabled(true);
    FinnWeb.loadUrl("http://m.finn.no");
    FinnWeb.requestFocus(View.FOCUS_DOWN);
    }
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        if (FinnWeb.canGoBack()) {
            FinnWeb.goBack();
        }
        else {
            System.exit(0);
        }
        return true;
}
    return super.onKeyDown(keyCode, event);
}
@Override
public boolean onCreateOptionsMenu(Menu meny) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menubuttons, meny);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch(item.getItemId()) {
    case R.id.LoggInn:
        setContentView(R.layout.main);
        FinnWeb  = (WebView) findViewById(R.id.FinnWeb);
        FinnWeb.setWebViewClient(new MyWebViewClient());
        FinnWeb.getSettings().setJavaScriptEnabled(true);
        FinnWeb.loadUrl("http://m.finn.no/#loginForm.html");
        FinnWeb.requestFocus(View.FOCUS_DOWN);
        break;
    case R.id.OmUtvikler:
        setContentView(R.layout.omutvikler);
        TilbakeButton = (Button)findViewById(R.id.TilbakeButton);
        TilbakeButton.setOnClickListener(this);
        break;
    case R.id.RegistrerDeg:
        setContentView(R.layout.main);
        FinnWeb  = (WebView) findViewById(R.id.FinnWeb);
        FinnWeb.setWebViewClient(new MyWebViewClient());
        FinnWeb.getSettings().setJavaScriptEnabled(true);
        FinnWeb.loadUrl("http://m.finn.no/#auth/registrer.html");
        FinnWeb.requestFocus(View.FOCUS_DOWN);
        break;
    case R.id.Tilbake:
        if (FinnWeb.canGoBack()) {
            FinnWeb.goBack();
        }
        else{

        }
        break;
    case R.id.Frem:
        if (FinnWeb.canGoForward()) {
            FinnWeb.goForward();
        }
        else{

        }
        break;
    case R.id.ExitWithSaving:
        FinnWeb.saveState(null);
        System.exit(0);
        break;
    case R.id.Exit:
        System.exit(0);
        break;
    case R.id.LastAnnose:
        FinnWeb.restoreState(null);
        break;
        }
    return true;
}
public void onClick(View src) {
    switch(src.getId()) {
    case R.id.TilbakeButton:
        setContentView(R.layout.main);
        FinnWeb  = (WebView) findViewById(R.id.FinnWeb);
        FinnWeb.setWebViewClient(new MyWebViewClient());
        FinnWeb.getSettings().setJavaScriptEnabled(true);
        FinnWeb.getSettings().setBuiltInZoomControls(true); 
        FinnWeb.requestFocus(View.FOCUS_DOWN);
        break;
    }
}
public boolean shouldOverrideUrlLoading(WebView view, String url) 
{   view.loadUrl(url);
    //save off url in instance variable
    return true;
 }

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

0 个答案:

没有答案