Code example for WebView: Displaying local web pages

Methods: clearViewgetSettingsloadData, refreshDrawableState

0
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.academic_calendar);
         
        mWebView = (WebView) findViewById(R.id.academic_webview);
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setBuiltInZoomControls(true);
         
        mYear = "2010";
         
        mYear2010 = (Button) findViewById(R.id.year_2010);
        mYear2010.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	mYear = "2010";
            	clearColor(); 
            	setColor(); 
            	loadUrl(); 
            } 
        }); 
         
        mYear2011 = (Button) findViewById(R.id.year_2011);
        mYear2011.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	mYear = "2011";
            	clearColor(); 
            	setColor(); 
            	loadUrl(); 
            } 
        }); 
         
        clearColor(); 
        setColor(); 
        loadUrl(); 
    } 
     
    private void loadUrl() { 
        AssetManager assetManager = getAssets();
         
        InputStream inputStream = null;
        try { 
        	if ( mYear == "2010" ) {
        	    inputStream = assetManager.open("academic_year_2010");
        	} else if (mYear == "2011") {
        		inputStream = assetManager.open("academic_year_2011");
        	} 
        } catch (IOException e) {
        	Log.e("tag", e.getMessage());
        } 
        String s = readTextFile(inputStream);
        mWebView.clearView();
		mWebView.loadData("Loading...", "text/html", "");
		mWebView.refreshDrawableState();
        mWebView.loadData(s, "text/html", "utf-8");
    } 
     
	private String readTextFile(InputStream inputStream) {
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		byte buf[] = new byte[1024];
Stop searching for code, let great code find you!  Add Codota to your java IDE