Articles

Affichage des articles associés au libellé source code

Android Mini project and tutorial : create and manage SQLite internal databases with Room persistence library with Kotlin

Image
  In this tutorial we will learn how to work with the Android Room library to create and manipulate internal SQLite databases in our android applications. Previously, we were able to create our database and our tables and manage our data thanks to SQLiteOpenHelper and SQLiteDatabase classes. This meant entering a large amount of standard code to create and manipulate even a very small database. In addition, no compile-time verification of  SQL queries was possible. And if the database schema is modified, we had to update the affected SQL queries. But now with Jetpack libraries we have become able to create and manipulate our internal databases in more flexible ways thanks to Room library. The Room library provides an abstraction layer on SQLite, which allows more robust access to the database while offering all the power of SQLite. Room is an ORM, Object Relational Mapping library. In other words, Room will map our database objects to Java objects and provide an abstraction layer on SQ

Android tutorial : Spinner basics

Image
The Spinner of Android is the equivalent of drop-down boxes that are found in some development kits (JComboBox in Java / Swing, for example). Press  central button of the terminal pad brings out a dropdownlist allowing the user making his choice. We can choose from a list without occupying the entire screen as with a ListView, but at the cost of an extra click. As ListView, we must provide the adapter for data and child views via setAdapter () and a listener is hung with setOnItemSelectedListener (). If you want to customize the display of the combo box, you must configure  the adapter, not the Spinner widget. To do this, we need a method therefore  setDropDownViewResource () for providing the identifier of the relevant picture. Here is a sample xml code to implement a simple view containing a Spinner: main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"      androi

Advanced use of Intents: Android StartActivityForResult Example

Image
In the previous tutorial   Android Tutorial : Using Intent to move from one activity to another and sending data via putExtra   , we saw the use of intent to move from one activity to another, today we will see how to  receive a result from the  second  activity.  The intent was instructed to call the second activity and through the startActivity method to display it.  Imagine that our secondary activit y has a result to return to the first activity.  Our objective is to   start a second activity that returns result “data” to first activity. At first c reate a new Android Application. File  >>  New  >>  Android Application Enter Project name:  StartActivity Keep other default selections, go  Next   until you reach  Finish In your layout folder you must have two Layouts XML files. The first XML file "activity_main.xml" must contain a Button and the second XML file "second_activity.xml" must contain an EditText and a Button. res/