Android Programs Day 5

Similar documents
Android Apps Development for Mobile and Tablet Device (Level I) Lesson 4. Workshop

Meniu. Create a project:

ANDROID PROGRAMS DAY 3

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Q.1 Explain the dialog and also explain the Demonstrate working dialog in android.

Create Parent Activity and pass its information to Child Activity using Intents.

Intents. Your first app assignment

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

05. RecyclerView and Styles

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

1. Location Services. 1.1 GPS Location. 1. Create the Android application with the following attributes. Application Name: MyLocation

Mobila applikationer och trådlösa nät, HI1033, HT2013

Our First Android Application

1. Simple List. 1.1 Simple List using simple_list_item_1

Basic GUI elements - exercises

<uses-permission android:name="android.permission.internet"/>

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Android Using Menus. Victor Matos Cleveland State University

Android Application Development. By : Shibaji Debnath

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126

Fragment Example Create the following files and test the application on emulator or device.

Tabel mysql. Kode di PHP. Config.php. Service.php

Dynamically Create Admob Banner and Interstitial Ads

Arrays of Buttons. Inside Android

Vienos veiklos būsena. Theory

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

Android Using Menus. Victor Matos Cleveland State University

Action Bar. (c) 2010 Haim Michael. All Rights Reserv ed.

Data Persistence. Chapter 10

Mobile and Ubiquitous Computing: Android Programming (part 3)


TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

@Bind(R.id.input_ ) EditText EditText Button _loginbutton;

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

StoppUhr. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start1"

Workshop. 1. Create a simple Intent (Page 1 2) Launch a Camera for Photo Taking


CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

M.A.D Assignment # 1

Mobile Software Development for Android - I397

android-espresso #androidespresso

Mobila applikationer och trådlösa nät, HI1033, HT2012

Introducing the Android Menu System

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Android HelloWorld - Example. Tushar B. Kute,

Managing Data. However, we'll be looking at two other forms of persistence today: (shared) preferences, and databases.

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

ActionBar. import android.support.v7.app.actionbaractivity; public class MyAppBarActivity extends ActionBarActivity { }

Tip Calculator. xmlns:tools=" android:layout_width="match_parent"

Fragments. Lecture 11

Preferences. Marco Ronchetti Università degli Studi di Trento

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

Mobile Programming Lecture 7. Dialogs, Menus, and SharedPreferences

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Android - Widgets Tutorial

Android/Java Lightning Tutorial JULY 30, 2018

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Android Application Model I. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

EMBEDDED SYSTEMS PROGRAMMING Android Services

Action Bar. Action bar: Top navigation bar at each screen The action bar is split into four different functional areas that apply to most apps.

APPENDIX CODE TO STORE THE BUTTON MENU AND MOVE THE PAGE

Group B: Assignment No 8. Title of Assignment: To verify the operating system name and version of Mobile devices.

API Guide for Gesture Recognition Engine. Version 2.0

Database Development In Android Applications


Android Apps Development for Mobile Game Lesson 5

Android - JSON Parser Tutorial

Android Application Model I

POCKET STUDY. Divyam Kumar Mishra, Mrinmoy Kumar Das Saurav Singh, Prince Kumar

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Accelerating Information Technology Innovation

1. Explain the architecture of an Android OS. 10M The following diagram shows the architecture of an Android OS.

ELET4133: Embedded Systems. Topic 15 Sensors

Android Coding. Dr. J.P.E. Hodgson. August 23, Dr. J.P.E. Hodgson () Android Coding August 23, / 27

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

Overview. What are layouts Creating and using layouts Common layouts and examples Layout parameters Types of views Event listeners

API Guide for Gesture Recognition Engine. Version 1.1

Mobile Application Development MyRent Settings

Android Workshop: Model View Controller ( MVC):

Have a development environment in 256 or 255 Be familiar with the application lifecycle

5Displaying Pictures and Menus with Views

Programmation Mobile Android Master CCI

android:orientation="horizontal" android:layout_margintop="30dp"> <Button android:text="button2"

Android Tutorial: Part 3

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics

Building MyFirstApp Android Application Step by Step. Sang Shin Learn with Passion!

Tutorial: Setup for Android Development

android:layout_margintop="5dp" > <EditText android:layout_width="210dp"

COMP61242: Task /04/18

Android CardView Tutorial

Time Picker trong Android

Android UI Development

Open Lecture Mobile Programming. Intro to Material Design

<uses-permission android:name="android.permission.internet" />

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

Transcription:

Android Programs Day 5 //Android Program to demonstrate the working of Options Menu. 1. Create a New Project. 2. Write the necessary codes in the MainActivity.java to create OptionMenu. 3. Add the oncreateoptionsmenu() in mainactivity.java after oncreate(). public boolean oncreateoptionsmenu(menu menu) super.oncreateoptionsmenu(menu); CreateMenu(menu); return super.oncreateoptionsmenu(menu); 4. Add oncreatemenu(menu) user-defined function. menu.add(0, 0, 0, "Item 1"): Arguements: 1: Group ID 2: Item ID 3: Order ID 4: Item Names private void CreateMenu(Menu menu) MenuItem mnu1 = menu.add(0, 0, 0, "Item 1"); MenuItem mnu2 = menu.add(0, 1, 1, "Item 2"); 5. Add onoptionsitemselected(menuitem). Any operation on items, will call this function and handle the events. public boolean onoptionsitemselected(menuitem item) return MenuChoice(item); 6. Add on MenuChoice(MenuItem) user-defined function. private boolean MenuChoice(MenuItem item)

switch (item.getitemid()) case 0: //Code Goes Here case 1: //Code Goes Here return false; 7. Run the code and test the working of OptionMenu. //MainActivity.java: import android.content.intent; import android.net.uri; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.toast; public class MainActivity extends AppCompatActivity protected void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); public boolean oncreateoptionsmenu(menu menu) super.oncreateoptionsmenu(menu); createmenu(menu); return super.oncreateoptionsmenu(menu); private void createmenu(menu menu) MenuItem menu1 = menu.add(0, 0, 0, "View A Contact"); MenuItem menu2 = menu.add(0, 1, 1, "Edit A Contact"); MenuItem menu3 = menu.add(0, 2, 2, "Dial A Contact"); MenuItem menu4 = menu.add(0, 3, 3, "View All");

public boolean onoptionsitemselected(menuitem item) return menuchoice(item); private boolean menuchoice(menuitem item) switch(item.getitemid()) case 0: Intent obj = new Intent(Intent.ACTION_VIEW); obj.setdata(uri.parse("content://contacts/people/1")); startactivity(obj); case 1: Intent obj1 = new Intent(Intent.ACTION_EDIT); obj1.setdata(uri.parse("content://contacts/people/1")); startactivity(obj1); case 2: Intent obj2 = new Intent(Intent.ACTION_DIAL); obj2.setdata(uri.parse("tel:+9876543210")); startactivity(obj2); case 3: Intent obj3 = new Intent(Intent.ACTION_VIEW); obj3.setdata(uri.parse("content://contacts/people/")); startactivity(obj3); //activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.ibmsap.test_optionmenu.mainactivity"> <TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content"

android:text="hello World" android:textappearance="@android:style/textappearance.large " tools:layout_constraintleft_creator="1" tools:layout_constrainttop_creator="1" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" tools:layout_constraintright_creator="1" android:layout_margintop="117dp" app:layout_constrainttop_totopof="parent" /> </android.support.constraint.constraintlayout>

//Android Program to demonstrate the working of Context Menu. 1. Create a New Project. 2. Add a Button in the UI. Write the necessary codes in the MainActivity.java to create ContextnMenu. 3. Add a Listener to the Button by writing the following code. Button btn = (Button)findViewById(R.id.button); btn.setoncreatecontextmenulistener(this); 4. Add the oncreatecontextmenu() in mainactivity.java after oncreate(). public void oncreatecontextmenu(contextmenu menu, View v,contextmenu.contextmenuinfo menuinfo) super.oncreatecontextmenu(menu, v, menuinfo); CreateMenu(menu); 5. Add on CreateMenu(menu) user-defined function. menu.add(0, 0, 0, "Item 1"): Arguements: 1: Group ID 2: Item ID 3: Order ID 4: Item Names private void CreateMenu(Menu menu) MenuItem mnu1 = menu.add(0, 0, 0, "Item 1"); MenuItem mnu2 = menu.add(0, 1, 1, "Item 2"); 6. Add oncontextitemselected(menuitem). Any operation on items, will call this function and handle the events. public boolean oncontextitemselected(menuitem item) return MenuChoice(item); 7. Add on MenuChoice(MenuItem) user-defined function.

private boolean MenuChoice(MenuItem item) switch (item.getitemid()) case 0: //Code Goes Here case 1: //Code Goes Here return false; 7. Run the code and test the working of ContextMenu. //MainActivity.java: import android.content.intent; import android.net.uri; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.contextmenu; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.button; import android.widget.toast; public class MainActivity extends AppCompatActivity Button btn; protected void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); btn = (Button)findViewById(R.id.button); btn.setoncreatecontextmenulistener(this); public void oncreatecontextmenu(contextmenu menu, View v, ContextMenu.ContextMenuInfo menuinfo) super.oncreatecontextmenu(menu, v, menuinfo); createmenu(menu);

private void createmenu(menu menu) MenuItem menu1 = menu.add(0, 0, 0, "View A Contact"); MenuItem menu2 = menu.add(0, 1, 1, "Edit A Contact"); MenuItem menu3 = menu.add(0, 2, 2, "Dial A Contact"); MenuItem menu4 = menu.add(0, 3, 3, "View All"); public boolean oncontextitemselected(menuitem item) return menuchoice(item); private boolean menuchoice(menuitem item) switch(item.getitemid()) case 0: Intent obj = new Intent(Intent.ACTION_VIEW); obj.setdata(uri.parse("content://contacts/people/1")); startactivity(obj); case 1: Intent obj1 = new Intent(Intent.ACTION_EDIT); obj1.setdata(uri.parse("content://contacts/people/1")); startactivity(obj1); case 2: Intent obj2 = new Intent(Intent.ACTION_DIAL); obj2.setdata(uri.parse("tel:+9876543210")); startactivity(obj2); case 3: Intent obj3 = new Intent(Intent.ACTION_VIEW); obj3.setdata(uri.parse("content://contacts/people/")); startactivity(obj3); //activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.ibmsap.test_optionmenu.mainactivity"> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="context Menu" tools:layout_constrainttop_creator="1" tools:layout_constraintright_creator="1" tools:layout_constraintbottom_creator="1" app:layout_constraintbottom_tobottomof="parent" app:layout_constraintright_torightof="parent" tools:layout_constraintleft_creator="1" app:layout_constraintleft_toleftof="parent" app:layout_constrainttop_totopof="parent" app:layout_constrainthorizontal_bias="0.417" app:layout_constraintvertical_bias="0.498" /> </android.support.constraint.constraintlayout>

//Android Program to demonstrate the Menu Creation using XML File. 1. Create a new project. 2. Create a Directory "menu" in /res folder. 3. Create a Menu resource file in /res/menu folder and name it as menu.xml 4. Add few <item> as buttons. //menu.xml: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu1" android:title="menu 1" /> <item android:id="@+id/menu2" android:title="menu 2" /> <item android:id="@+id/menu3" android:title="menu 3" /> </menu> 5. Add oncreateoptionsmenu(menu) and use MenuInflater object to populate the menu isng menu.xml file. public boolean oncreateoptionsmenu(menu menu) MenuInflater menuinflater = getmenuinflater(); menuinflater.inflate(r.menu.menu, menu); return super.oncreateoptionsmenu(menu);

6. Add onoptionsitemselected(menuitem). Any operation on items, will call this function and handle the events. public boolean onoptionsitemselected(menuitem item) return MenuChoice(item); //MainActivity.java: import android.content.intent; import android.net.uri; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; public class MainActivity extends AppCompatActivity protected void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); public boolean oncreateoptionsmenu(menu menu) MenuInflater obj = getmenuinflater(); obj.inflate(r.menu.menu, menu); return super.oncreateoptionsmenu(menu); public boolean onoptionsitemselected(menuitem item) return menuchoice(item); private boolean menuchoice(menuitem item) switch(item.getitemid()) case R.id.Menu1: Intent obj = new Intent(Intent.ACTION_VIEW); obj.setdata(uri.parse("content://contacts/people/1")); startactivity(obj);

case R.id.Menu2: Intent obj1 = new Intent(Intent.ACTION_EDIT); obj1.setdata(uri.parse("content://contacts/people/1")); startactivity(obj1); case R.id.Menu3: Intent obj2 = new Intent(Intent.ACTION_DIAL); obj2.setdata(uri.parse("tel:+9876543210")); startactivity(obj2); case R.id.Menu4: Intent obj3 = new Intent(Intent.ACTION_VIEW); obj3.setdata(uri.parse("content://contacts/people/")); startactivity(obj3); //activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.ibmsap.test_menuxml.mainactivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello World!" app:layout_constraintbottom_tobottomof="parent" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constrainttop_totopof="parent" /> </android.support.constraint.constraintlayout> //menu.xml: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/menu1" android:title="view A Contact"/> <item android:id="@+id/menu2" android:title="edit A Contact"/> <item android:id="@+id/menu3" android:title="dial A Contact"/> <item android:id="@+id/menu4" android:title="view All Contacts"/> </menu>

//Android Program to demonstrate the Sub-Menu Creation using XML File. 1. Create a new project. 2. Create a Directory "menu" in /res folder. 3. Create a Menu resource file in /res/menu folder and name it as menu.xml 4. To add Sub menu follow these steps. i. Create an <item> tag in the menu.xml file. ii. Create a <menu> tag inside the <item> tag. This will act as Main menu 1. iii. Create few <item> tags in the <menu> tag. Give proper id and titles. These will act as Sub-menu 1. iv. Repeat the steps i to iv to create one more sub-menu. //menu.xml: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/mainmenu1" android:title="main Menu 1"> <menu android:title="sub Menu1"> <item android:id="@+id/menu1" android:title="view A Contact"/> <item android:id="@+id/menu2" android:title="edit A Contact"/> </menu> </item> </menu>

5. Add oncreateoptionsmenu(menu) and use MenuInflater object to populate the menu isng menu.xml file. public boolean oncreateoptionsmenu(menu menu) MenuInflater menuinflater = getmenuinflater(); menuinflater.inflate(r.menu.menu, menu); return super.oncreateoptionsmenu(menu); 6. Add onoptionsitemselected(menuitem). Any operation on items, will call this function and handle the events. public boolean onoptionsitemselected(menuitem item) return MenuChoice(item); //MainActivity.java: import android.content.intent; import android.net.uri; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; public class MainActivity extends AppCompatActivity protected void oncreate(bundle savedinstancestate) super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); public boolean oncreateoptionsmenu(menu menu) MenuInflater obj = getmenuinflater(); obj.inflate(r.menu.menu, menu); return super.oncreateoptionsmenu(menu); public boolean onoptionsitemselected(menuitem item) return menuchoice(item);

private boolean menuchoice(menuitem item) switch(item.getitemid()) case R.id.Menu1: Intent obj = new Intent(Intent.ACTION_VIEW); obj.setdata(uri.parse("content://contacts/people/1")); startactivity(obj); case R.id.Menu2: Intent obj1 = new Intent(Intent.ACTION_EDIT); obj1.setdata(uri.parse("content://contacts/people/1")); startactivity(obj1); case R.id.Menu3: Intent obj2 = new Intent(Intent.ACTION_DIAL); obj2.setdata(uri.parse("tel:+9876543210")); startactivity(obj2); case R.id.Menu4: Intent obj3 = new Intent(Intent.ACTION_VIEW); obj3.setdata(uri.parse("content://contacts/people/")); startactivity(obj3); //activity_main.xml: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.ibmsap.test_menuxml.mainactivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello World!" app:layout_constraintbottom_tobottomof="parent" app:layout_constraintleft_toleftof="parent" app:layout_constraintright_torightof="parent" app:layout_constrainttop_totopof="parent" /> </android.support.constraint.constraintlayout>

//menu.xml: <?xml version="1.0" encoding="utf-8"?> <menu xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/mainmenu1" android:title="main Menu 1"> <menu android:title="sub Menu1"> <item android:id="@+id/menu1" android:title="view A Contact"/> <item android:id="@+id/menu2" android:title="edit A Contact"/> </menu> </item> <item android:id="@+id/mainmenu2" android:title="main Menu 2"> <menu android:title="sub Menu2"> <item android:id="@+id/menu3" android:title="dial A Contact"/> <item android:id="@+id/menu4" android:title="view All Contacts"/> </menu> </item> </menu>