Java 16 Mobile phones and Android (Poul Klausen) (z-library.sk, 1lib.sk, z-lib.sk)

Author: Poul Klausen

Java

No Description

📄 File Format: PDF
💾 File Size: 6.3 MB
6
Views
0
Downloads
0.00
Total Donations

📄 Text Preview (First 20 pages)

ℹ️

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

📄 Page 1
(This page has no text content)
📄 Page 2
2 POUL KLAUSEN JAVA 16: MOBIL PHONES AND ANDROID SOFTWARE DEVELOPMENT Download free eBooks at bookboon.com
📄 Page 3
3 Java 16: Mobil phones and Android: Software Development 1st edition © 2018 Poul Klausen & bookboon.com ISBN 978-87-403-2330-6 Peer review by Ove Thomsen, EA Dania Download free eBooks at bookboon.com
📄 Page 4
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT Contents 4 CONTENTS Foreword 7 1 Introduction 9 Exercise 1: Calculations 22 2 Widgets 24 2.1 A Zipcode app 27 Exercise 2: People 35 3 Layout 37 3.1 RelativeLayout 37 3.2 LinearLayout 47 3.3 TableLayout 51 3.4 GridLayout 51 3.5 A ConstraintLayout 57 3.6 Containers 60 Exercise 3: People1 73 Download free eBooks at bookboon.com Click on the ad to read more www.sylvania.com We do not reinvent the wheel we reinvent light. Fascinating lighting offers an infinite spectrum of possibilities: Innovative technologies and new markets provide both opportunities and challenges. An environment in which your expertise is in high demand. Enjoy the supportive working atmosphere within our global group and benefit from international career paths. Implement sustainable ideas in close cooperation with other specialists and contribute to influencing our future. Come and join us in reinventing light every day. Light is OSRAM
📄 Page 5
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT Contents 5 4 User interaction 74 4.1 A context menu 76 4.2 A main menu 82 4.3 Define a menu in XML 87 Exercice 4: ImageApp 88 4.4 About activities 90 4.5 Multiple activities 94 Problem 1: LoanApp 96 5 Files 99 5.1 Reading resources 99 Exercise 5: Zipcodes 103 5.2 Ordinary files 103 5.3 Internal storage 104 Exercise 6: NameBook 117 Problem 2: PuzzleApp 119 6 SQLite 121 6.1 Creates a Database 124 6.2 SQL SELECT 128 6.3 SQL INSERT, UPDATE and DELETE 132 6.4 The other activities 137 Exercise 7: PhoneBook 137 7 Threads 141 8 Services 149 8.1 The class Intent 153 8.2 ServiceApp1 154 8.3 ServiceApp2 158 8.4 ServiceApp3 161 8.5 ServiceApp4 164 8.6 ServiceApp5 169 8.7 Ring the phone 172 8.8 A local service – ServiceApp 176 8.9 Services and SQLite 184 Download free eBooks at bookboon.com
📄 Page 6
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT Contents 6 9 A final example 196 9.1 Project start and MainActivity 196 9.2 The data access layer 198 9.3 Notes 199 9.4 Anniversaries 201 9.5 Appointments 202 9.6 The other tools 202 9.7 A project review 206 Appendix A, installing of Android Studio 207 Download free eBooks at bookboon.com
📄 Page 7
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT Foreword 7 FOREWORD The current book is the sixteenth in this series of books on software development in Java, and it is at the same time the first of two books that focus on developing applications for Android, and especially for mobile phone applications. The books requires basic knowledge of Java and system development in general, and the goal is that the reader, after reading this book, is able to write simple applications to an Android phone. Important topics are the most common widgets, layouts and basically about activities, but also use of files and databases are processed. Mobile phone programming is in many ways different from programming to a usual computer, for example because the phone is another machine than a traditional computer, and the phone and, for that matter, other Android devices like tablets have other features that are not available on a PC. However, these features are dealt with in the following book. As the title says this series of books deals with software development, and the goal is to teach the reader how to develop applications in Java. It can be learned by reading about the subject and by studying complete sample programs, but most importantly by yourself to do it and write your own programs from scratch. Therefore, an important part of the books is exercises and problems, where the reader has to write programs that correspond to the substance being treated in the books. All books in the series is built around the same skeleton and will consist of text and examples and exercises and problems that are placed in the text where they naturally belongs. The difference between exercises and problems is that the exercises largely deals with repetitions of the substance that is presented in the text, and furthermore it is relatively accurately described what to do. Problems are in turn more loosely described, and are typically a little bigger and there is rarely any clear best solution. These are books to be read from start to finish, but the many code examples, including exercises and problems plays a central role, and it is important that the reader predict in detail studying the code to the many examples and also solves the exercises and problems or possibly just studying the recommended solutions. All books ends with one or two larger sample programs, which focus primarily is on process and an explanation of how the program is written. On the other hand appears the code only to a limited extent – if at all – and the reader should instead study the finished program code perhaps while testing the program. In addition to show the development of programs that are larger than the examples, which otherwise is presented, the aim of the concluding examples also is to show program examples from varying fields of application. Most books also ends with an appendix dealing with a subject that would not be treated in the books. It may be issues on the installation of software or other topics in computer Download free eBooks at bookboon.com
📄 Page 8
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT Foreword 8 technology, which are not about software development, but where it is necessary to have an introductory knowledge. If the reader already is familiar with the subject, the current appendix can be skipped. The programming language is, as mentioned Java, and besides the books use the following products: 1. etBeans as IDE for application development 2. MySQL to the extent there is a need for a database server (from the book Java 6 onwards) 3. GlassFish as a web server and application server (from the book Java 11 onwards) 4. Android Studio, that is a tool to development of apps to mobil phones It is products that are free of charge and free to install, and there is even talk about products, where the installation is progressing all by itself and without major efforts and challenges. In addition, there are on the web detailed installation instructions for all the three products. The products are available on Windows and Linux, and it therefore plays no special role if you use Linux or Windows. All sample programs are developed and tested on machines running Linux. In fact, it plays no major role, as both Java and other products work in exactly the same way whether the platform is one or the other. Some places will be in the books where you could see that the platform is Linux, and this applies primarily commands that concerning the file system. Otherwise it has no meaning to the reader that the programs are developed on a Linux machine, and they can immediately also run under Windows unless a program refers to the file system where it may be necessary to change the name of a file. Finally a little about what the books are not. It is not “how to write” or for that matter reference manuals in Java, but it is as the title says books on software development. It is my hope that the reader when reading the books and through the many examples can find inspiration for how to write good programs, but also can be used as a source collection with a number of examples of solutions to concrete everyday programming problems that you regularly face as a software developer. Download free eBooks at bookboon.com
📄 Page 9
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 9 1 INTRODUCTION In short, this book is about programming mobile phones, and although it is in principle not so different from writing programs to a regular PC, there are also significant differences. Firstly, the programs are written in Java so that side of the case should be in place, but what makes the programmming different are differences in the hardware. Android is used as an operating system on a variety of devices such as mobile phones, tablets, smart TV, and so on, and although the starting point for this book is a smart phone, they are also widely different with different screen sizes and other options. Furthermore, the development of the mobile phone market is so fast that writing programs for the latest mobile phones you can not be sure they are supported by only a few phones. Thus, there are a whole host of new factors to consider when writing applications for mobile phones. As a development tool, for the rest of this book, I will use Android Studio, an IDE from Google. Appendix A explains how to download and install the product and what it takes to set up an Android application development environment. In the following, I would like to assume that Android Studio is installed and in the rest of this section, I will show you how to write a simple application that can convert kilometers to miles and the other way, convert miles to kilometers, and it is so a little more than Hello World. I want to focus on what you should do, but not so much about how it all works, which I want to postpone for later. I start by opening Android Studio. Is it the first time you opens the program you get the following window: Download free eBooks at bookboon.com
📄 Page 10
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 10 Here I click on the top link Start a new Android Studio project, and the result is the following window where I have to enter the project name (here KmMiles), and where in the file system that the project should be created: I have also entered a Company domain name, which is usually a web address, and the name is included in the project’s package name. When you click Next, you get a window: Download free eBooks at bookboon.com
📄 Page 11
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 11 where to choose what it is for an application that you want to create and what version of the operating system you want to support. I have chosen that the application should be Phone and Tablet and that it should support API 22 for Android 5.1. You should note that Android Studio writes that I can expect my application to run on 62.6 percent of all devices. Instead, if I had chosen the latest version, I would like to know that my application could run on less than 1 percent of all devices. In the next window, you must select the activity for the phone that corresponds to the overall layout of the screen and what elements should be on it: In this case, I have chosen Empty Activity, which is default. In the next window again, select the name for that activity, which becomes a class name, and you must also choose the name for the layout. There is no special reasons for choosing other names than what Android Studio has done as default, so I keep the names. When you click Next, you get a window where Android Studio builds the project and you then have to click Finish. Is it the first time you run the program, Android Studio ask you to download more files, what you should do, and after Android Studio opening the window with the program’s code, you may also need to click on a few download links, but then the project has been created and ready and you can start programming. Download free eBooks at bookboon.com
📄 Page 12
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 12 Download free eBooks at bookboon.com Click on the ad to read more Click on the ad to read more © Deloitte & Touche LLP and affiliated entities. 360° thinking. Discover the truth at www.deloitte.ca/careers © Deloitte & Touche LLP and affiliated entities. 360° thinking. Discover the truth at www.deloitte.ca/careers © Deloitte & Touche LLP and affiliated entities. 360° thinking. Discover the truth at www.deloitte.ca/careers © Deloitte & Touche LLP and affiliated entities. 360° thinking. Discover the truth at www.deloitte.ca/careers
📄 Page 13
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 13 Below is a screenshot of Android Studio after the project has been created: On the left side you have an overview of the project’s files, which I do not want to mention further in this place. Otherwise, there are two tabs, where the first shows the application layout, while the other shows a Java class that corresponds to a main class in a conventional Java application. The layout is called activity_main and is an XML document that defines the user interface. You can work with the document both in design mode where you can place components using the mouse, or you can work directly in the XML code. You can switch between the two modes by clicking on the bottom tabs (Design and Text). The project is actually a complete application that you can build and test. To test the program, click the green arrow after app in the toolbar. When you do, you get the following window: Download free eBooks at bookboon.com
📄 Page 14
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 14 where to choose which device to test the program on. The first time the window is empty. There is no device connected, but you can create a virtual device by clicking the bottom button. Here you will first get an overview of which virtual devices are available. When I created the project, I chose that the application has to support API 22, and so I must choose a virtual device that does. I have chosen Nexus 4, and in the next window you will need to download the current device. It requires some downloads, but when that happens, you have a virtual device as shown in the above window. When I then click OK, Android Studio will open the emulator (see below). It takes a while, because you have to download the emulator itself, and it takes a long time to start, but with a little hassle, you get a window that simulates a phone and with the current application active. For the time being, the application is trivial as it does nothing but write a text in the window. I will now expand the program from what Android Studio has auto generated to an application that opens an emulator as shown below, that is, an application where you can enter a number and then click on the Convert button, and depending on which radio button are checked, the number entered is interpreted as miles or kilometers and the number is converted to a value in the opposite unit. That’s a classic conversion program. It is of course a very simple program that consists of - a text field - two radio buttons - and two push buttons but it is nevertheless a program that performs a data processing and not just shows a text. Download free eBooks at bookboon.com
📄 Page 15
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 15 Download free eBooks at bookboon.com Click on the ad to read more Click on the ad to read more We will turn your CV into an opportunity of a lifetime Do you like cars? Would you like to be a part of a successful brand? We will appreciate and reward both your enthusiasm and talent. Send us your CV. You will be surprised where it can take you. Send us your CV on www.employerforlife.com
📄 Page 16
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 16 To write the program I will start in the design window and drag components from the toolbox to the design window’s Component Tree : The design originally had a component that showed the text Hello World. I’ve deleted this component, and then I added - a LinearLayout, there is some kind of layout manager - a EditText (a Plain Text), there is an input field - a RadioGroup, which is a container for components - two RadioButton components - a LinearLayout - two Button components Download free eBooks at bookboon.com
📄 Page 17
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 17 You should note that the design panel shows how the individual components are nested in a hierarchy. Also note that if you select a component with the mouse, you get a panel on the right side of the window, where you can specify properties for that component. If you examine the project files, see the app | res | values, there is a file called strings.xml. It is an XML document that defines strings and other resources that the application can apply and only one is defined, which is the program’s name. I have expanded the file with 5 new definitions, the first 4 being texts for radio buttons and other buttons, while the last is for the background color of the window: JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT INTRODuCTION 17 You should note that the design panel shows how the individual components are nested in a hierarchy. Also note that if you select a component with the mouse, you get a panel on the right side of the window, where you can specify properties for that component. If you examine the project files, see the app | res | values, there is a file called strings.xml. It is an XML document that defines strings and other resources that the application can apply and only one is defined, which is the program’s name. I have expanded the file with 5 new definitions, the first 4 being texts for radio buttons and other buttons, while the last is for the background color of the window: <resources> <string name="app_name">KmMiles</string> <string name="km">Kilometers to miles</string> <string name="ml">Miles to kilometers</string> <string name="ok">Convert</string> <string name="cl">Clear</string> <color name="bgColor">#F5F5DC</color> </resources> I will then display the finished XML for the user interface, which is essentially autogenerated by the designer window, but where I made some adjustments: <?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" android:background="@color/bgColor" tools:context="dk.data.torus.kmmiles.MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_marginTop="20dp" android:layout_marginStart="20dp"> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:inputType="numberSigned|numberDecimal"/> <RadioGroup android:id="@+id/radioGroup1" android:layout_width="match_parent" android:layout_height="match_parent"> I will then display the finished XML for the user interface, which is essentially autogenerated by the designer window, but where I made some adjustments: JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT INTRODuCTION 17 You should note that the design panel shows how the individual components are nested in a hierarchy. Also note that if you select a component with the mouse, you get a panel on the right side of the window, where you can specify properties for that component. If you examine the project files, see the app | res | values, there is a file called strings.xml. It is an XML document that defines strings and other resources that the application can apply and only one is defined, which is the program’s name. I have expanded the file with 5 new definitions, the first 4 being texts for radio buttons and other buttons, while the last is for the background color of the window: <resources> <string name="app_name">KmMiles</string> <string name="km">Kilometers to miles</string> <string name="ml">Miles to kilometers</string> <string name="ok">Convert</string> <string name="cl">Clear</string> <color name="bgColor">#F5F5DC</color> </resources> I will then display the finished XML for the user interface, which is e sentially autogenerated by the designer window, but where I made some adjustments: <?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" android:background="@color/bgColor" tools:context="dk.data.torus.kmmiles.MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_marginTop="20dp" android:layout_marginStart="20dp"> <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:ems="10" android:inputType="numberSigned|numberDecimal"/> <RadioGroup android:id="@+id/radioGroup1" android:layout_width="match_parent" android:layout_height="match_parent"> Download free eBooks at bookboon.com
📄 Page 18
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 18 JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT INTRODuCTION 18 <RadioButton android:id="@+id/radioButton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="@string/ml" /> <RadioButton android:id="@+id/radioButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/km" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="@string/cl" android:onClick="onClick"/> Download free eBooks at bookboon.com Click on the ad to read more Click on the ad to read more “In Denmark you can find great engineering jobs and develop yourself professionally. Especially in the wind sector you can learn from the best people in the industry and advance your career in a stable job market.” Mireia Marrè, Advanced Engineer from Spain. Working in the wind industry in Denmark since 2010. Are you looking to further your cleantech career in an innovative environment with excellent work/life balance? Think Denmark! Visit cleantech.talentattractiondenmark.com DENMARK IS HIRING
📄 Page 19
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 19 JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT INTRODuCTION 19 <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="@string/ok" android:onClick="onClick"/> </LinearLayout> </RadioGroup> </LinearLayout> </android.support.constraint.ConstraintLayout> When you see the code, you can not of course know that it should be written in this way, but you can easily understand the code and the meaning of the individual lines. You should especially note how to create an identifier for a component (for a widget), such as android:id="@+id/editText1" You should also note how to refer to resources (defined in strings.xml ), and as an example: android:text="@string/km" Finally, note that an event handler has been defined for the two buttons. Basically, the document defines what components the window should have and how it should be laid out, and in addition, for each widget, a number of attributes are defined with values for corresponding properties for the objects that the finished program must consists of. To perform the conversion, I have added a class named Converter to the directory (or package in the project pane) app | java | dk.data.torus.kmmiles: package dk.data.torus.kmmiles;public class Converter { private static final double factor = 1.609344; public static double toKm(double miles) { return miles * factor; } public static double toMl(double kilometers) { return kilometers / factor; } } When you see the code, you can not of course know that it should be written in this way, but you can easily understand the code and the meaning of the individual lines. You should especially note how to create an identifier for a component (for a widget), such as JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT INTRODuCTION 19 <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:text="@string/ok" android:onClick="onClick"/> </LinearLayout> </RadioGroup> </LinearLayout> </android.support.constraint.ConstraintLayout> e see t e c e, ca t f c rse t at it s l e ritte i t is a , t ca easil ersta t e c e a t e ea i f t e i ivi al li es. s l es eciall te t create a i e tifier f r a c e t (f r a i get), s c as android:id="@+id/editText1" You should also note how to refer to resources (defined in strings.xml ), and as an example: android:text="@string/km" Finally, note that an event handler has been defined for the two buttons. Basically, the document defines what components the window should have and how it should be laid out, and in addition, for each widget, a number of attributes are defined with values for corresponding properties for the objects that the finished program must consists of. To perform the conversion, I have added a class named Converter to the directory (or package in the project pane) app | java | dk.data.torus.kmmiles: package dk.data.torus.kmmiles;public class Converter { private static final double factor = 1.609344; public static double toKm(double miles) { return miles * factor; } public static double toMl(double kilometers) { return kilometers / factor; } } s l als te t refer t res rces ( efi e i stri gs.x l ), a as a exa le: Finally, note that an event handler has been defined for the two buttons. Basically, the document defines what components the window should have and how it should be laid out, and in addition, for each widget, a number of attributes are defined with values for corresponding properties for the objects that the finished program must consists of. To perform the conversion, I have added a class named Converter to the directory (or package in the project pane) app | java | dk.data.torus.kmmiles: JAVA 16: MOBIL PH NES AND ANDROID: SOFTWARE DEVELOPMENT INTRODuCTION 19 <Button id="@+id/button2" widt ="wrap_content" hei ht="wrap_content" layout_ma ginT p="20dp" text="@string/o ndroid:onClick="onClick"/> </L nearLayout> </RadioGr p </LinearLayout> </android.support.constraint.ConstraintLayout> When you see the code, you can n t of course know that it should be written in this way, but you can easily understand the code and the meaning of the indivi ual lines. You should especially note how to create an identifier for a component (for a widget), such as android:id="@+id/editText1" You should also note how to refer to resources (defined in strings.xml ), and as an example: android:text="@string/km" i all , te t at a eve t a ler as ee efi e f r t e t tt s. asicall , t e c e t efi es at c e ts t e i s l ave a it s l e lai t, a i a iti , f r eac i et, a er f attri tes are efi e it val es f r c rres i r erties f r t e jects t at t e fi is e r ra st c sists f. erf r t e c versi , I ave a e a class a e o verter t t e irect r ( r ac a e i t e r ject a e) | j v | . t .tor s. iles: package dk.data.torus.kmmiles;public class Converter { rivate static fina double factor = 1.609344; public static double toKm(double miles) { return miles * factor; } public static double toMl(double kilometers) { return kilometers / factor; } } Download free eBooks at bookboon.com
📄 Page 20
JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT IntroduCtIon 20 The class is obviously trivial and is included solely to show that an Android application can contain Java classes in the same way as other Java applications and that it is just a usual Java class. Back there is the main class MainActivity: JAVA 16: MOBIL PHONES AND ANDROID: SOFTWARE DEVELOPMENT INTRODuCTION 20 The cla s is obviously trivial and is included solely to show that an Android a plication can contain Java cla ses in the same way as other Java a plications and that it is just a usual Java cla s. Back there is the main cla s MainActivity: package dk.data.torus.kmmiles; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.RadioButton; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void onClick(View view) { EditText text = (EditText) findViewById(R.id.editText1); if (view.getId() == R.id.button1) { text.setText(""); } else if (view.getId() == R.id.button2) { RadioButton ml = (RadioButton) findViewById(R.id.radioButton1); RadioButton km = (RadioButton) findViewById(R.id.radioButton2); if (text.getText().length() == 0) { Toast.makeText(this, "Please enter a valid number", Toast.LENGTH_LONG).show(); return; } double value = Double.parseDouble(text.getText().toString()); if (ml.isChecked()) text.setText(String.valueOf(Converter.toKm(value))); else text.setText(String.valueOf(Converter.toMl(value))); } } } Download free eBooks at bookboon.com
The above is a preview of the first 20 pages. Register to read the complete e-book.

💝 Support Author

0.00
Total Amount (¥)
0
Donation Count

Login to support the author

Login Now
Back to List