1 / 13

Android Programming - Features

Android Programming - Features. Lecture 4/5 Zablon Ochomo zochomo@icontrace.com. Android Programming. Java Netbeans Android SDK www.nbandroid.org for instructions on how to setup android for Netbeans IDE SDK Manager AVD Manager Android Packages. Android Menus. Menu types:

gaetan
Download Presentation

Android Programming - Features

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android Programming - Features Lecture 4/5 ZablonOchomo zochomo@icontrace.com

  2. Android Programming • Java • Netbeans • Android SDK • www.nbandroid.org 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="http://schemas.android.com/apk/res/android"> <item android:id="@+id/official" android:icon="@drawable/odm_bullet" android:title="Official" /> <item android:id="@+id/stories" android:icon="@drawable/odm_bullet" android:title="Stories" /> <item android:id="@+id/community" android:icon="@drawable/odm_bullet" android:title="Community news" /> <item android:id="@+id/tv" android:icon="@drawable/odm_bullet" android:title="Orange TV" /> <item android:id="@+id/ittt" android:icon="@drawable/odm_bullet" android:title="About it and tt" /></menu>

  5. Inflating the menu from XML @Override public booleanonCreateOptionsMenu(Menu menu) { MenuInflaterinflater = 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 booleanonOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.official: mWebView.loadUrl("http://www.odm.co.ke"); return true; case R.id.community: mWebView.loadUrl("http://www.odm.co.ke"); return true; case R.id.stories: mWebView.loadUrl("http://www.odm.co.ke"); return true; case R.id.tv: mWebView.loadUrl("http://www.odm.co.ke"); return true; case R.id.ittt: mWebView.loadUrl("http://www.icontrace.com"); return true; 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 { WebViewmWebView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mWebView = (WebView) findViewById(R.id.webview); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.loadUrl("http://www.odm.co.ke"); mWebView.setWebViewClient(new ODMWebViewClient()); } @Override public booleanonCreateOptionsMenu(Menu menu) { MenuInflaterinflater = getMenuInflater(); inflater.inflate(R.menu.party_menu, menu); return true; } @Override public booleanonOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.official: mWebView.loadUrl("http://www.odm.co.ke"); return true; case R.id.community: mWebView.loadUrl("http://www.odm.co.ke"); return true; case R.id.stories: mWebView.loadUrl("http://www.odm.co.ke"); return true; case R.id.tv: mWebView.loadUrl("http://www.odm.co.ke"); return true; case R.id.ittt: mWebView.loadUrl("http://www.icontrace.com"); return true; default: return super.onOptionsItemSelected(item); } } private class ODMWebViewClient extends WebViewClient { @Override public booleanshouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } } }

  11. Permission in the manifest file <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.siasakenya.android.siasa" android:versionCode="1" android:versionName="1.0"> <application android:label="@string/app_name" android:icon="@drawable/odm1"> <activity android:name="MainActivity" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"> <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"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageViewandroid:id="@+id/logoImage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:src="@drawable/logo"/> <WebView android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </LinearLayout>

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

More Related