Android Programming Tutorials

(Romina) #1
Browsing Some Posts

package apt.tutorial.two;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;

public class HelpPage extends Activity {
private WebView browser;

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.help);

browser=(WebView)findViewById(R.id.webkit);
browser.loadUrl("file:///android_asset/help.html");
}
}

Note how we use file:///android_asset/help.html as the URL syntax to


reach into our APK's assets to load the desired Web page.


Finally, as normal, we need to add another element to our


AndroidManifest.xml file:


<activity android:name=".HelpPage">
</activity>

Step #4: Splice In the Help Activity


Right now, the option menu in Patchy for help launches the HelpCast


activity. We want to change that so Patchy launches HelpPage instead, then


augment HelpPage to display HelpCast on demand.


Making the change to display HelpPage is easy – just replace the HelpCast


reference with HelpPage in onOptionsItemSelected():


startActivity(new Intent(this, HelpPage.class));

At this point, if you rebuild and reinstall the application, then click on the


help menu item, you will see your help page in a full-screen browser.


253
Free download pdf