Presentation is loading. Please wait.

Presentation is loading. Please wait.

Android Programming - Features

Similar presentations


Presentation on theme: "Android Programming - Features"— Presentation transcript:

1 Android Programming - Features
Lecture 4/5 Zablon Ochomo

2 Android Programming Java Netbeans Android SDK
for instructions on how to setup android for Netbeans IDE SDK Manager AVD Manager Android Packages

3 Android Menus Menu types:
Context menu: is the menu in context/associated with some object. Long-press on the view will bring up the registered Context menu. Option menu: menu opened when MENU key on the device is clicked. Icon menu contain 1st six options while expanded menu are available when More button is clicked Sub menus: is the nested menu that can be added to any type of menu (options or context menu)

4 Options menu example Refer to “siasa” app provided on the cource website. Check under resources/menu folder for “party_menu.xml” <?xml version="1.0" encoding="UTF-8"?><menu xmlns:android=" > <item android:title="Official" /> <item android:title="Stories" /> <item android:title="Community news" /> <item android:title="Orange TV" /> <item android:title="About it and tt" /></menu>

5 Inflating the menu from XML
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.party_menu, menu); return true; } Add this code snippet on your Activity code.

6 Add event listener to your menu
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.official: mWebView.loadUrl(" return true; case R.id.community: case R.id.stories: case R.id.tv: case R.id.ittt: mWebView.loadUrl(" default: return super.onOptionsItemSelected(item); }

7 Android Dialog A dialog is usually a small window that appears in front of the current Activity. The underlying Activity loses focus and the dialog accepts all user interaction. Dialogs are normally used for notifications that should interupt the user and to perform short tasks that directly relate to the application in progress (such as a progress bar or a login prompt). The Dialog class is the base class for creating dialogs. However, you typically should not instantiate a Dialog directly. Instead, you should use one of the following subclasses:

8 Android Dialog AlertDialog A dialog that can manage zero, one, two, or three buttons, and/or a list of selectable items that can include checkboxes or radio buttons. The AlertDialog is capable of constructing most dialog user interfaces and is the suggested dialog type. ProgressDialog A dialog that displays a progress wheel or progress bar. Because it's an extension of the AlertDialog, it also supports buttons. DatePickerDialog A dialog that allows the user to select a date. See the Hello DatePicker tutorial. TimePickerDialog A dialog that allows the user to select a time. If you would like to customize your own dialog, you can extend the base Dialog object or any of the subclasses listed above and define a new layout.

9 Web View WebView allows you to create your own window for viewing web pages (or even develop a complete browser). In this tutorial, you'll create a simple Activity that can view and navigate web pages.

10 Activity package com.siasakenya.android.siasa; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.webkit.WebView; import android.webkit.WebViewClient; public class MainActivity extends Activity { WebView public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl(" mWebView.setWebViewClient(new ODMWebViewClient()); } public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.party_menu, menu); return true; public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.official: case R.id.community: case R.id.stories: case R.id.tv: case R.id.ittt: mWebView.loadUrl(" default: return super.onOptionsItemSelected(item); private class ODMWebViewClient extends WebViewClient { public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url);

11 Permission in the manifest file
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android=" package="com.siasakenya.android.siasa" android:versionCode="1" android:versionName="1.0"> <application <activity android:name="MainActivity" <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-permission android:name="android.permission.INTERNET" /> </manifest>

12 Layout for WebView Widget support
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:layout_height="wrap_content" android:layout_alignParentBottom="true" <WebView android:layout_height="fill_parent"/> </LinearLayout>

13 Lab project Check the siasa and Androworks netbeans project for web view List view, menus, menu actions and dialogs


Download ppt "Android Programming - Features"

Similar presentations


Ads by Google