Tip Calculator. xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

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

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

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

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

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


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

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.

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Basic GUI elements - exercises

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

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

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

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

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


else if(rb2.ischecked()) {

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

ANDROID PROGRAMS DAY 3

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

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

M.A.D Assignment # 1

Create a local SQL database hosting a CUSTOMER table. Each customer includes [id, name, phone]. Do the work inside Threads and Asynctasks.

User Interface Development in Android Applications

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

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

Manifest.xml. Activity.java

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

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

SD Module-1 Android Dvelopment

Adaptation of materials: dr Tomasz Xięski. Based on presentations made available by Victor Matos, Cleveland State University.

Arrays of Buttons. Inside Android

Simple Currency Converter

Produced by. Mobile Application Development. Eamonn de Leastar

Database Development In Android Applications

Mobile Software Development for Android - I397

Android Apps Development for Mobile Game Lesson 5

Fragments. Lecture 11

Time Picker trong Android

ELET4133: Embedded Systems. Topic 15 Sensors

Data Persistence. Chapter 10

使用 TensorFlow 設計矩陣乘法計算並轉移執行在 Android 上 建國科技大學資管系 饒瑞佶 2017/8

Android - JSON Parser Tutorial

Android Programs Day 5

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

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

Lecture 14. Android Application Development

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

LAMPIRAN PROGRAM. public class ListArrayAdapterPost extends ArrayAdapter<ModelDataPost> {

Android Application Development. By : Shibaji Debnath

Intents. Your first app assignment

Android UI Development

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

PROGRAMMING APPLICATIONS DECLARATIVE GUIS

Dynamically Create Admob Banner and Interstitial Ads

Chapter 5 Flashing Neon FrameLayout

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

APPENDIX CODE TO STORE THE BUTTON MENU AND MOVE THE PAGE

Practical 1.ListView example

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

An Overview of the Android Programming

05. RecyclerView and Styles

Starting Another Activity Preferences

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

Our First Android Application

Chapter 8 Positioning with Layouts

EMBEDDED SYSTEMS PROGRAMMING Android Services

Android CardView Tutorial

B9: Việc cuối cùng cần làm là viết lại Activity. Tới Example.java và chỉnh sửa theo nội dung sau: Mã: package at.exam;

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

Text Properties Data Validation Styles/Themes Material Design

Android JSON Parsing Tutorial

Laying Out Controls in Containers

TPCT s College of Engineering, Osmanabad. Laboratory Manual SDL-II. Mobile Application Development (Android) For. Third Year Students (CSE)

Android Layout Types

Android Data Storage

Press project on the left toolbar if it doesn t show an overview of the app yet.

THE CATHOLIC UNIVERSITY OF EASTERN AFRICA A. M. E. C. E. A

public AnimLayer(Context context, AttributeSet attrs, int defstyle) { super(context, attrs, defstyle); initlayer(); }

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

Adapter.

Android Basics. Android UI Architecture. Android UI 1

Introduction. Who Should Read This Book. Key Topics That This Book Covers

Android Workshop: Model View Controller ( MVC):

1. Simple List. 1.1 Simple List using simple_list_item_1

COMP61242: Task /04/18

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

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

South Africa

Vienos veiklos būsena. Theory

A-1. Listing Program. CariKata.java. package com.indah.kmp;

Hangman Requirements

Tutorial: Setup for Android Development

Debojyoti Jana (Roll ) Rajrupa Ghosh (Roll ) Sreya Sengupta (Roll )

Serious Gaming. Technical manual. This document is a collection of the code and installation process

TextView. A label is called a TextView. TextViews are typically used to display a caption TextViews are not editable, therefore they take no input

package import import import import import import import public class extends public void super new this class extends public super public void new

List-Based Widgets: Lists, Grids, and Scroll Views

Android/Java Lightning Tutorial JULY 30, 2018

Transcription:

Tip Calculator activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity"> android:id="@+id/billamountlabel" android:text="@string/bill_amount_label" android:padding="10dp"

android:textsize="20sp" android:textstyle="bold" /> <EditText android:id="@+id/billamountedittext" android:layout_alignbaseline="@+id/billamountlabel" android:layout_torightof="@+id/billamountlabel" android:layout_marginleft="5dp" android:ems="8" android:inputtype="numberdecimal" android:text="@string/bill_amount" android:textsize="20sp" > <requestfocus/> </EditText> android:id="@+id/percentlabel" android:layout_alignleft="@+id/billamountlabel" android:layout_below="@+id/billamountlabel" android:padding="10dp" android:text="@string/tip_percent_label" android:textsize="20sp" android:textstyle="bold" /> android:id="@+id/percenttextview"

android:layout_alignbaseline="@id/percentlabel" android:layout_alignleft="@+id/billamountedittext" android:padding="5dp" android:text="@string/tip_percent" android:textsize="20sp" android:layout_below="@+id/billamountedittext" /> <Button android:id="@+id/percentdownbutton" android:layout_width="45dp" android:layout_height="45dp" android:layout_alignbaseline="@id/percenttextview" android:layout_marginleft="25dp" android:layout_torightof="@+id/percenttextview" android:text="@string/decrease" android:textsize="20sp" /> <Button android:id="@+id/percentupbutton" android:layout_width="45dp" android:layout_height="45dp" android:layout_alignbaseline="@id/percentdownbutton" android:layout_torightof="@+id/percentdownbutton" android:text="@string/increase" android:textsize="20sp" /> android:id="@+id/tiplabel"

android:layout_alignleft="@+id/percentlabel" android:layout_below="@+id/percentlabel" android:padding="10dp" android:text="@string/tip_amount_label" android:textsize="20sp" android:textstyle="bold" /> android:id="@+id/tiptextview" android:layout_alignbaseline="@id/tiplabel" android:layout_alignleft="@id/billamountedittext" android:padding="5dp" android:text="@string/tip_amount" android:textsize="20sp" /> android:id="@+id/totallabel" android:layout_alignleft="@id/tiplabel" android:layout_below="@id/tiplabel" android:padding="10dp" android:text="@string/total_amount_label" android:textsize="20sp" android:textstyle="bold" /> android:id="@+id/totaltextview"

android:layout_alignbaseline="@id/totallabel" android:layout_alignleft="@id/tiptextview" android:padding="5dp" android:text="@string/total_amount" android:textsize="20sp" /> </RelativeLayout> TipCalculatorActivity.java package com.raymundoconnor.tipcalculator; import android.app.activity; import android.content.dialoginterface; import android.widget.textview; import android.os.bundle; import android.view.keyevent; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.edittext; import android.widget.textview; import android.widget.textview.oneditoractionlistener; import java.text.numberformat; public class TipCalculatorActivity extends Activity implements OnEditorActionListener, OnClickListener {

// defines instances variables for the widgets private EditText billamountedittext; private TextView percenttextview; private Button percentupbutton; private Button percentdownbutton; private TextView tiptextview; private TextView totaltextview; // defines instance variable for tip percent private float tippercent =.15f; @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); //get references to the widgets billamountedittext = (EditText)findViewById(R.id.billAmountEditText); percenttextview = (TextView)findViewById(R.id.percentTextView); percentupbutton = (Button)findViewById(R.id.percentUpButton); percentdownbutton = (Button)findViewById(R.id.percentDownButton); tiptextview = (TextView)findViewById(R.id.tipTextView); totaltextview = (TextView)findViewById(R.id.totalTextView); // set the listeners billamountedittext.setoneditoractionlistener(this); percentupbutton.setonclicklistener(this); percentdownbutton.setonclicklistener(this); // calculate the tip and display results calculateanddisplay(); private void calculateanddisplay() { //get the bill amount

String billamountstring = billamountedittext.gettext().tostring(); float billamount; if (billamountstring.equals("")){ billamount=0; else { billamount=float.parsefloat(billamountstring); //calculate tip and total float tipamount = billamount * tippercent; float totalamount = billamount + tipamount; //display the results with formatting NumberFormat currency = NumberFormat.getNumberInstance(); tiptextview.settext(currency.format(tipamount)); totaltextview.settext(currency.format(totalamount)); NumberFormat percent = NumberFormat.getPercentInstance(); percenttextview.settext(percent.format(tippercent)); @Override public void onclick(view v) { switch (v.getid()){ case R.id.percentDownButton: tippercent = tippercent -.01f; calculateanddisplay(); break; case R.id.percentUpButton: tippercent = tippercent +.01f; calculateanddisplay(); break;

@Override public boolean oneditoraction(textview v, int actionid, KeyEvent event) { calculateanddisplay(); return false;