Android Programming in Kotlin Starting With An App 1st Edition James pdf download
Android Programming in Kotlin Starting With An App 1st Edition James pdf download
https://ebookname.com/product/android-programming-in-kotlin-
starting-with-an-app-1st-edition-james/
https://ebookname.com/product/android-programming-in-java-
starting-with-an-app-3rd-edition-james/
https://ebookname.com/product/android-development-with-
kotlin-1st-edition-marcin-moskala/
https://ebookname.com/product/android-game-programming-for-
dummies-1st-edition-derek-james/
https://ebookname.com/product/quintilian-on-the-teaching-of-
speaking-and-writing-translations-from-books-one-two-and-ten-of-
the-institutio-oratoria-2nd-edition-james-j-murphy/
Moral Character An Empirical Theory 1st Edition
Christian B. Miller
https://ebookname.com/product/moral-character-an-empirical-
theory-1st-edition-christian-b-miller/
https://ebookname.com/product/hiv-and-the-pathogenesis-of-
aids-3rd-edition-jay-a-levy/
https://ebookname.com/product/mastering-technical-communication-
skills-a-student-s-handbook-1st-edition-edition-peter-wide/
https://ebookname.com/product/autistic-spectrum-disorders-in-the-
early-years-1st-edition-lynn-plimley/
https://ebookname.com/product/turbulence-coherent-structures-
dynamical-systems-and-symmetry-2ed-edition-holmes-p/
The House Will Come to Order How the Texas Speaker
Became a Power in State and National Politics 1st
Edition Patrick L. Cox
https://ebookname.com/product/the-house-will-come-to-order-how-
the-texas-speaker-became-a-power-in-state-and-national-
politics-1st-edition-patrick-l-cox/
Android Programming In Kotlin:
Starting with an App
First Edition
Mike James
I/O Press
I Programmer Library
Copyright © 2017 IO Press
All rights reserved. This book or any portion thereof may not be reproduced
or used in any manner whatsoever without the express written permission of
the publisher except for the use of brief quotations in a book review.
The publisher recognizes and respects all marks used by companies and
manufacturers as a means to distinguish their products. All brand names and
product names mentioned in this book are trade marks or service marks of
their respective companies and our omission of trade marks is not an attempt
to infringe on the property of others.
In particular we acknowledge that Android is a trademark of Google.
2
Preface
Android programming is an attractive proposition. There are more Android
users than any other smartphone or tablet and this makes it a potentially huge
market. Android devices are relatively cheap and this makes it suitable for
implementing smaller scale projects. Finally the tools that you need are free
to download and use and you don’t need anyone's permission to get started.
The only difficulty is that the Android is a tough system to master. It is easy
enough to get started as Android Studio will build you a Hello World app in a
few minutes, but what you do next is more difficult. The good news is that
Kotlin is a language that makes working with Java and Android much easier.
You cannot get away from Java in Android as it is the language used for the
libraries that your apps are built on, but Kotlin makes writing code so much
easier and it works with Java code perfectly. As a programmer who has
worked in both Java and Kotlin, I can vouch for the fact that Kotlin is a
pleasure to work with and an excellent choice.
You can get a surprisingly long way in Android programming by simply
copying and pasting code from other programs that roughly do what you
want, but the results are usually unreliable and disappointing. To create a
good app there is no substitute for understanding how the system works and
appreciating its strong points and its limitations.
This book aims not only to show you how common tasks are done in
Android, but to make sure that you understand the reasons they are done in a
particular way. This means covering not just the what but also the why. The
good news is that this isn’t as difficult as you might expect because Android
does have repeating patterns and ways of doing things and once you have
seen something in action you find it generalizes to components you haven’t
encountered.
This isn’t a book full of complete examples and case studies. In fact the
examples are stripped down to their bare minimum to avoid having to present
lines of irrelevant and repetitious code and to let you see what is essential. It
also isn’t a complete treatment of everything Android. A single book that
covered every aspect of the Android system would be too large to pick up and
carry. Instead it focuses on the things you need to know to write a simple app.
It focuses on creating the user interface (UI) because this is what you spend
most of your time working on even if the app in question is sophisticated. At
least 90% of the effort in creating any app goes into building and perfecting
the UI and this makes it the key place to start. In this book you will find out
how to build an app with a single Activity and a UI. If you master this level of
the art then you will find it much easier to push on into unknown territory.
3
It is assumed that you can program, but not necessarily in Kotlin or Java – any
general object-oriented language will do as a starting point. As long as you are
happy with the idea of a loop, conditional, function and what objects are,
then you should have no problem working with Kotlin and Android.
Finally the development tool used is the latest version of Android Studio
because it doesn’t make sense not to use it or to use anything else.
This is the place to start.
Mike James
December 2017
There are additional articles on I Programmer that form the basis of the more
advanced books that are still in preparation. After updating and revision,
Android Adventures – Mastering Fragments will be published in print as
Android Programming: Mastering Fragments & Dialogs. The first draft of
Android Programming: Structuring a Complex App, which goes further into
threading, concurrency, life cycle and other topics crucial to a real world app,
is currently work in progress on the website.
4
Table of Contents
Chapter 1
Getting Started With Android Studio 11
The Language Choice........................................................................12
What You Need to Know..................................................................13
Making a Start...................................................................................13
Your First Program............................................................................15
First Look...........................................................................................18
The IDE..............................................................................................19
Basic Project Structure......................................................................19
Anatomy of an Activity.....................................................................20
Hello Layout Editor...........................................................................21
Inspecting the XML...........................................................................26
The Kotlin..........................................................................................27
Getting Started with the Emulator ...................................................28
Summary...........................................................................................32
Chapter 2
Activity and User Interface 33
The MainActivity..............................................................................34
Inside the Activity.............................................................................35
View and ViewGroup........................................................................36
Creating Our First UI.........................................................................38
Properties & Attributes......................................................................42
Events................................................................................................43
Connecting the Activity to the UI.....................................................44
Finding View Objects........................................................................48
Summary...........................................................................................51
Chapter 3
Building a Simple UI 53
What's in the Palette..........................................................................54
The Button an Example....................................................................56
Positioning – the ConstraintLayout..................................................56
Sizing.................................................................................................64
The Component Tree........................................................................65
A Simple Button Example – Baseline Alignment............................66
Orientation and Resolution..............................................................67
A First App – Simple Calculator.......................................................73
Summary...........................................................................................81
5
Chapter 4
Android Events 83
How Java Passes Functions...............................................................83
Android Events..................................................................................84
The Kotlin Object..............................................................................85
Passing Functions In Kotlin..............................................................87
Function References..........................................................................87
Anonymous Functions......................................................................89
The Lambda.......................................................................................89
Events Using Lambdas......................................................................90
Closure...............................................................................................91
Using Breakpoints.............................................................................93
Modern Java Event Handling............................................................94
Summary...........................................................................................96
Chapter 5
Basic Controls 99
Basic Input Controls..........................................................................99
Button Styles and Properties............................................................99
All Attributes...................................................................................104
Text Fields.......................................................................................105
The onEditorAction Event..............................................................108
CheckBoxes.....................................................................................109
Switches and Toggle buttons..........................................................110
Radio Buttons .................................................................................111
Summary.........................................................................................113
Chapter 6
Working With Layouts 115
Understanding Layouts...................................................................115
Layout Properties............................................................................116
Width and Height............................................................................118
Units................................................................................................118
A Control is Just a Box....................................................................120
Gravity.............................................................................................121
The FrameLayout............................................................................122
LinearLayout....................................................................................124
RelativeLayout.................................................................................128
Summary.........................................................................................133
6
Chapter 7
The ConstraintLayout 135
Automatic Constraints....................................................................136
Manual Constraints.........................................................................141
Bias Constraints...............................................................................143
Chains..............................................................................................144
A Chained Keypad..........................................................................147
Guidelines........................................................................................151
Groups.............................................................................................152
Sizing...............................................................................................153
Barriers............................................................................................158
Troubleshooting..............................................................................161
Summary.........................................................................................163
Chapter 8
Programming The UI 165
A UI Library.....................................................................................165
The View.........................................................................................165
Using setContentView.....................................................................166
The ViewGroup...............................................................................168
Programming Layout Properties.....................................................169
The View Hierarchy........................................................................171
XML Layout.....................................................................................171
Inflation Theory..............................................................................172
Finding View objects.......................................................................173
How to Build a UI?..........................................................................174
Summary.........................................................................................176
Chapter 9
Menus – Toolbar 177
Creating a Menu Resource..............................................................177
The Menu Tree................................................................................178
Displaying a Menu..........................................................................180
Using the Toolbar............................................................................181
Creating the App Bar ......................................................................185
Where's My Toolbar?.......................................................................186
Responding to Menu Events...........................................................186
Changing Menus in Code................................................................189
Controlling the Toolbar...................................................................192
Summary.........................................................................................193
7
Chapter 10
Menus – Context & Popup 195
The Context Menu..........................................................................195
Contextual Action Bar.....................................................................199
The Popup Menu.............................................................................202
Summary.........................................................................................204
Chapter 11
Resources 205
Why Use Resources?.......................................................................205
What are Resources?.......................................................................207
Drawables........................................................................................209
Values..............................................................................................211
IDs....................................................................................................212
Accessing Resources in Code – The R Object................................213
Conditional Resources....................................................................214
A Simple Localization.....................................................................218
Android Studio Translation Tools.................................................219
Summary.........................................................................................221
Chapter 12
Bitmap Graphics 223
Android Graphics............................................................................223
The Bitmap......................................................................................223
The ImageView Control..................................................................224
Canvas..............................................................................................225
A First Graphic................................................................................227
Transformations..............................................................................229
A Logical Approach to Transforms................................................232
Setting Your Own Coordinates.......................................................233
Simple Animation...........................................................................234
Timer and Threads..........................................................................236
Listing..............................................................................................239
Summary.........................................................................................242
8
Chapter 13
Life Cycle Of An Activity 243
Lifetime and State...........................................................................243
The Life Cycle of an App................................................................244
The Simple Approach.....................................................................245
Lifecycle Explorer...........................................................................246
Trying It Out....................................................................................247
Retaining State – the Bundle..........................................................248
Saving Additional UI Data..............................................................250
Complex UI Elements.....................................................................251
Advanced State Management.........................................................252
Summary.........................................................................................253
Chapter 14
Spinners 255
The Spinner and the Layout Editor................................................255
Introducing the ArrayAdapter........................................................257
Handling the Selection...................................................................259
Creating an ArrayAdapter from a Resource...................................262
Changing The List...........................................................................262
Summary.........................................................................................264
Chapter 15
Pickers 265
Working with Pickers......................................................................265
TimePicker.......................................................................................266
TimePicker in Code.........................................................................267
Updating the Time..........................................................................268
DatePicker........................................................................................269
Number Picker.................................................................................272
Multi-Digit Input.............................................................................276
Summary.........................................................................................279
Chapter 16
ListView 281
Understanding the Adapter............................................................281
Extending the ListAdapter Class....................................................282
Using the ArrayAdapter..................................................................283
Working with the Data....................................................................285
A Custom Layout.............................................................................288
A Custom ArrayAdapter.................................................................291
Reuse, Caching and General Layouts.............................................295
Custom Adapter..............................................................................298
Summary.........................................................................................299
9
Chapter 17
Android The Kotlin Way 301
What You No Longer Have To Type...............................................301
var & val...........................................................................................302
No More get & set............................................................................302
View Objects As Properties.............................................................304
Event Handlers................................................................................304
Data..................................................................................................306
Null Safety.......................................................................................307
Java Types and Null........................................................................308
Kotlin Aims to Help........................................................................310
Summary.........................................................................................311
10
Chapter 1
Android represents a big potential market. It is also the most open of the "big"
phone and tablet platforms. You can write a program for an Android and let
your friends have a copy, keep it to yourself or put it on sale in an app store.
Android phones and tablets are comparatively cheap and this makes it easier
to get started. What is even better, all the tools you need to create an Android
app are free. You don't need to pay anything to create, or distribute, your
Android apps. If you want to sell them using a well known marketplace there
may something to pay – there is a one-time fee of $25 to register for Google
Play, but you don't have to use any particular distribution method.
All that stands between you and your Android app is your imagination and
programming ability. I can't do much to improve your imagination, but I can
help with the programming side of things. If you are new to Android
programming this is the place to start.
In this book I will show you the fundamentals of Android programming. Not
the tips and tricks, but how to think about what is going on. You'll be
introduced to the general principles that will make it possible for you to
master anything that you encounter that is new in the future. It isn’t possible
to cover all of Android in one book as the subject is very large. Instead we
focus on the basics of creating a User Interface (UI) as all apps have to have
some way of interacting with a user.
There are many ways to create an Android app but Google's Android Studio is
an easy to use Android IDE – Integrated Development Environment – and it is
now the recommended way of doing the job.
Before Android Studio you had to use the Eclipse IDE and set up the SDK and
other pieces of software needed. This wasn't difficult, but Android Studio
eliminates extra steps and it makes programming Android easy. Put simply, it
is the way of the future and so worth your investment in learning it.
With the release of Android Studio Google stopped work on the Eclipse
plugin and this means that Android Studio really is the only way to develop
apps from now on.
11
The Language Choice
With the release of Android Studio 3 you now have a choice of programming
in Java or Kotlin. The advantage of Java is that it is a well known and well
supported language. If you already program in Java or want to acquire the
skill then you might well be better off starting with Android Programming In
Java: Starting with an App ISBN: 978-1871962550
Kotlin may be a be a new language but it is already well supported for the
simple reason that it is 100% compatible with Java. The Android libraries are
all written in Java, but Kotlin can make use of them with no problems. It is
this that makes Kotlin Android development possible. What is more, you
aren’t restricted to Kotlin in a project. You can add Java code to your new
Kotlin project and you can add Kotlin code to an existing Java project.
Put simply, there is very little risk involved in moving to Kotlin and there is a
lot to be gained. Kotlin is a much simpler and cleaner language than Java. It
has had the benefit of seeing how Java evolved and avoiding those mistakes.
Kotlin attempts to get straight to the point. In Java you tend to write some
code over and over and it can be time consuming and hides the simplicity of
what you are trying to do. Whenever this happens Kotlin modifies the
language so that you can express what you are doing succinctly. Programmers
moving from Java to Kotlin generally find that they like it because they get
more done with less typing. Programmers who only know Kotlin don’t know
how lucky they are!
Kotlin does things differently from Java and while you can pick up the
language as you go you might like to read Programmer's Guide To Kotlin
ISBN:978-1871962536. It isn’t necessary, as long as you know Java or another
object-oriented language, you can pick up Kotlin as you develop your
Android apps but I recommend learning the finer points of the language
sooner or later. It pays off to know your language.
The way Kotlin is used and the ways it changes Android programming in
particular are introduced as we go along. However, the final chapter is a brief
look at the major influences of Kotlin on Android programming. If you want a
quick overview before you start then read the final chapter, but in many ways
it makes more sense to read it as a summary after you have encountered the
ideas in context.
The bottom line is that, unless you have a commitment to Java, you probably
should start new projects in Kotlin and convert existing projects to Kotlin a
bit at a time.
12
What You Need to Know
You need to be able to program in a modern object-oriented language. Java
would be best as it is closest to Kotlin, but C++, C#, Visual Basic or anything
similar are close enough in spirit to Java for you to be able to cope. You might
well need to look things up about the specifics of particular features of Kotlin,
but most of the time it should be obvious, or obvious with the help of a few
comments.
It isn't necessary to be an expert programmer because for a lot of Android
programming you are simply using the features and facilities provided. That
is, a lot of Android programming is just a matter of following the rules.
However, if you hope to produce something unique and useful you will at
some point have to add something of your own – and here creativity and skill
are required. So you might not need to be an expert programmer to get
started, but you need to become one by the time you create your amazing app.
Fortunately practice is a good teacher and so learning to make the most of
Android Studio will actually help you learn to code.
Making a Start
I'm not going to spend a lot of time explaining how to install Android Studio
in a step-by-step way as the Android website does a good job and it is more
likely to be up-to-date. It is worth, however, going over the basic principles.
https://developer.android.com/studio/
The installer will download everything you need including the JDK.
Windows:
1. Launch the downloaded EXE file,
android-studio-bundle-<version>.exe.
2. Follow the setup wizard to install Android Studio.
Mac OS X:
1. Open the downloaded DMG file,
android-studio-bundle-<version>.dmg
2. Drag and drop Android Studio into the Applications folder.
13
Linux:
1. Unpack the downloaded ZIP file,
android-studio-bundle-<version>.tgz,
into an appropriate location for your applications.
2. To launch Android Studio, navigate to the
android-studio/bin/
directory in a terminal and execute studio.sh. You may want to add
android-studio/bin/
to your PATH environmental variable so that you can start Android
Studio from any directory.
Accept any defaults that the setup program offers you – unless you have a
good reason not to. It installs not only Android Studio, but the SDK and the
virtual device system that lets you test your application.
14
Your First Program
You can opt to start Android Studio after the installation. You will probably
not get straight to Android Studio the first time it starts as it downloads
updates to itself and to the Android SDK. You just have to be patient.
When it finally gets going you will see the Android Studio welcome screen:
If you have already created some programs you might well see them listed in
Recent projects.
Assuming this is your first project select the option:
Start a new Android Studio project
15
You can ignore the details of the new project for the moment. All you have to
do is supply a name for your application – HelloWorld in this case. Also make
sure you have Include Kotlin support ticked – this is what makes the project
use Kotlin rather than Java. Accept the other defaults that Android Studio
has filled in for you.
When you click Next you are given the chance to pick what devices you are
targeting. Again simply accept the defaults:
Most of the time you will want to create apps that run on a version of Android
that captures the biggest market but if this isn't a concern then it can be better
to select a more recent Android version.
16
The next page lets you select a template for your project. In this case change
the selection to Basic Activity. This gives you some additional generated code
which makes the app easier to create an app that looks right. Every Android
application consists of at least one Activity and this template generates a
project with a single Activity ready for you to customize:
On the next page you can assign custom names for the various components of
your project that the template generates. For a real project you would assign
names that were meaningful but in this case you can accept the defaults:
Finally you can click the Finish button and wait as Android Studio creates all
the files you need. Even a simple Android project has lots of files so again it
all takes time.
17
First Look
When everything is ready you will see Android Studio for the first time.
As long as everything has worked you should eventually, it takes about three
minutes or more, be presented with a view of your new project starting off in
the Layout Editor:
Problems?
If you get any error messages then the chances are that your project hasn't
finished being processed. Wait a little while longer for the activity to stop. If
you look at the status line at the bottom of the window you will see a message
saying “Gradle Build Finished” when Android Studio has finished with your
new project.
If you still have problems it is worth trying the File,Invalidate Caches/Restart
command. This usually works for "Missing styles" and similar errors.
18
The IDE
Although there looks like a lot to master in Android Studio's user interface,
most of it you will only visit occasionally. The key things to notice are that
moving from left to right you have:
● The Project window
● The tool Palette and the Component Tree window
● The Layout Editor
● The Attributes window
Most of the time you will be using the Project window and the Attributes
window. You will also see different editors depending on what sort of file
you have selected. In this case you have by default a layout file,
content_main.xml, selected and hence you have a layout editor in the middle
of the screen.
Before we go into layout, which is one of the main topics of this book, it is
important that you know a little about the file structure of a project so that
you can navigate to its different parts.
It seems almost unbelievable that the simplest Android app you can create
involves so many files.
19
Don't panic. Most of the files that have been created are auto-generated and
most of the time you don't need to know anything about them, let alone open
or edit them. In fact opening and editing auto-generated files really isn't a
good idea.
So let's focus on the files that matter to us.
For our simple program there are only two important files. One of them
determines the behavior of the Activity:
MainActivity.kt
The other determines the visual appearance, or View, of the app:
content_main.xml
You can set which Activity is the one that the system starts, but by default it
is the single activity that you created and named when you set up the project.
You can change the default names but for the moment leave them as they are.
Despite this being a Kotlin project, the java directory, from your point of view,
is where most of the construction of your app occurs, so make sure you know
where it is. The res directory is where you store all of the resources, layouts,
bitmaps, etc, that your app needs.
So while things look complicated at the moment the only two project files
that matter to you, and your project, are MainActivity.kt in the java folder
and content_main.xml in the res folder.
The two other folders in the java folder are concerned with creating tests for
your program. This is not something that we need to worry about when first
starting to write Android apps.
Anatomy of an Activity
An Android app is made up of one or more Activity classes.
You can think of an Activity as being something like a web page complete
with HTML to determine what displays and JavaScript to determine what it
does.
In the case of an Activity the layout is determined by the XML file in resource
(res) folder, this is often called the View, and the behavior is determined by
the Kotlin or Java code in the java folder.
The XML can be thought of as a markup language much like HTML or XAML.
It defines an initial layout for the screen when the app first runs. It is possible
to generate new layout components at runtime from the Java file. In fact, if
you really want to, you can dispense with the XML file and generate
everything from code, but as you will discover the XML markup approach is
much the best way to do the job because of the availability of the Layout
Editor.
20
So to be 100% clear in a Kotlin project:
● The kt file contains the code that makes your app behave in particular
ways.
● The .xml layout file contains a definition of the initial UI, the View, of
your app.
You can switch between editing the XML as text, and editing it in the drag-
and-drop Layout Editor simply by clicking on the tab. If you now click on the
tab the window will display the Layout Editor but be patient the first time
you do this it might take a few moments.
21
The Layout Editor looks a little too much to take in when you first see it but
you will quickly get used to it. On the left is a Palette of all of the components
or controls - buttons, text, checkboxes and so on - that you can place on the
design surface:
In the middle is the design surface and this defaults to the screen size and
appearance of the Nexus 5. You can select other devices to work with.
22
There are, in fact, two views of the layout that you can use, the design and the
blueprint. By default you are shown the design view but you can display
either view using the menu at the top left of the design area.
You can display both views together but in most cases available screen area is
the main issue and showing just one is the best option. The design view
shows you the layout as a close approximation to how it will appear on a real
device. The blueprint view doesn’t try to render the UI realistically but it does
provide you will more layout information to help you position and size
elements. Use whichever you are most happy with.
23
On the left, below the Palette, you have the Component Tree which shows
you the structure of your layout, that is how different UI components are
contained inside others. It shows you the structure of the XML file in an
easier to use form. You can use the Component Tree as an easy way of to
select individual UI components by clicking on their names. You can also
drag-and-drop UI components onto the Component Tree to position them
accurately within the hierarchy.
On the right you have the Attributes window that can be used to set the
attributes, such as width, height, color and so on of any component in the
layout. If you have used any drag-and-drop Layout Editor then this will seem
familiar and if you have struggled with detailed layout using a markup
language, be it HTML, XAML or XML, you will appreciate how easy the
Layout Editor makes building and testing a UI.
In the case of our sample program the only component is a single TextView
already containing the text "Hello World". A TextView is the standard
component to use when all we want to do is to display some static text.
24
You can modify the greeting text if you want to. Select the TextView
component either on the design or in the Component Tree and use the
Attributes window to find its Text attribute. Change this to read "Hello
Android World":
Use the text field without the spanner icon. The properties with the spanner
icon next to them are used to set values that only show in the Layout Editor.
In this case the text field without the spanner icon is the one that controls
what appears in your app at runtime.
You can use the Layout Editor to create any UI you care to and you really
don't have to get involved in the XML that corresponds to the layout – unless
things go wrong or you need to do something so sophisticated that the Layout
Editor doesn't support it.
25
Random documents with unrelated
content Scribd suggests to you:
Pokebroc
Hundred de Sutton
Hundred de Albodestowe
Hundred de Wardon
The only writer, it would seem, who has used this important survey is
Bridges, who refers to it throughout in his Northamptonshire as of the
time of 'Henry II'. A good instance of the confusion caused by this
assumption is seen in the remarks of Bridges as to Barnack (ii. 491),
where he is puzzled by our record, giving as its lord, not Gervase
Paynell, but Fulc Paynell (who was really his grandfather). To refute
his conclusion, it is sufficient to refer to the first name entered—that
of 'Albricus Camerarius'. This was no other than Aubrey de Vere, a
trusted minister of Henry I, who was made by him Great Chamberlain
in 1133, and who was slain in May 1141.8 His Northamptonshire
estate descended to his younger son, Robert, who, as 'Robertus filius
Albrici Camerarii', made his return as a Northamptonshire 'baron' in
1166.9 There can, therefore, be no confusion between Aubrey the
Chamberlain (d. 1141) and his eldest son and namesake. Yet if, from
the occurrence of his name, we pronounced the date of this survey to
be 1133-41, we should be in error. There are names belonging to an
earlier, as to a later, date than this.
Among the earliest are 'Ricardus filius Wydonis', the son and
successor of Guy de Raimbercurt, a great Domesday tenant-in-chief;
Walter fitz Winemar, whose father was both a tenant in capite and
under-tenant in Domesday; and Ralf fitz Oger, whose name illustrates
the value of these early surveys; for the entry proves that Oger, the
Northamptonshire tenant-in-chief (D.B., i. 228), was identical with
Oger 'Brito', the Lord of Bourne, Linc. (i. 364b), and that the son and
successor of this Oger was Ralf. We also recognize Roger Marmion,
who was succeeded, under Henry I, by Robert; Nigel de Albini, the
founder of the house of Mowbray; Michael de Hanslape, who died
under Henry I; and 'Robertus filius Regis', who became Earl of
Gloucester circ. 1122. Other tenants, living temp. Hen. I, are William
de Mandeville,10 William Meschin, Richard Basset, Viel (Vitalis)
Engaine, Baldwin fitz Gilbert, and Brian fitz Count. As for Ascelin de
Waterville and Alouf de Merke, they are found as under-tenants in
Domesday itself. On the other hand, such a name as 'Comes Warenn
de Morteyn' points to the latter years of Stephen's reign, or to the
early days of that of Henry II; while the mention of the earldoms of
Arundel, Ferrers (Derby) and Essex preclude, of course, an earlier
date than 1140.
Just below, in the case of Hemington, also a Vill of five hides, which
was equally divided between the Abbeys of Peterborough and
Ramsey, we read in Domesday that 'iii. milites' held the Peterborough
half (221b). Our survey enables us to distinguish their tenancies—
Richard fitz Gilbert holding a hide and three-eighths; Guy Maufe, five-
eighths of a hide, and Reginald le Moyne the same.15 But we can go
further and identify the first, from his holding, as the son of Gilbert
Fauvel, the Domesday tenant (see p. 138); while the second was the
heir, and probably the son of Roger Malfed (see p. 132).
At the close of the survey I have here discussed there is a list of the
knights of Peterborough (fos. 99b, 100) holding in Northamptonshire.
It ought to be carefully compared with the one I have examined
above (p. 131), being, it seems probable, about a generation later.
Such entries as these, at least, are conclusive for the holding to which
they refer:
Paganus de Roger
Helpestun fil[ius]
terciam Pagan[i]
partem unius in
militis Helpestun
(Chronicon terciam
Petroburgense, partem i.
p. 171). militis
(Vesp. E.
xxii., fo.
100).
In the same way, Roger Marmion had been succeeded by Robert. This
second list is of special value from the fact that the Peterborough
carta of 1166 gives no particulars of the knights or of their fees.
1 Or Sh——.
13 Since this was written I have come across a curious confirmation of the
hypothesis advanced. In the Lindsey Survey (Ed. Greenstreet), an entry on
fo. 20, in the original ran: 'Comes Odo [tenet] in Aldobi', above which a
later hand has interlined, 'De feodo Comitis Albemerle'. It is curious that in
the same survey another later interlineation—'Comes Lincoln'—was, though
distinguished by Hearne, incorporated with the text by Mr Waters (see p.
151).
Now this solution of the difficulty will scarcely, I venture to think, bear
the test of investigation. It appears to have originated in Dr Stubbs'
suggestion that there must have been, between the days of Henry I
and of William I, 'some skilful organizing hand working with neither
justice nor mercy'5—a suggestion subsequently amplified into the
statement that it is to Ranulf Flambard 'without doubt that the
systematic organization of the exactions' under William Rufus 'is to be
attributed',6 and that by him 'the royal claims were unrelentingly
pressed', his policy being 'to tighten as much as possible the hold
which the feudal law gave to the king on all feudatories temporal and
spiritual'.7 There is nothing here that can be called in question, but
there is also nothing, be it observed, to prove that either 'feudal law'
or 'military tenure' was introduced by Ranulf Flambard. Indeed, with
his usual caution and unfailing sound judgment, our great historian is
careful to admit that 'it is not quite so clear' in the case of the lay as
of the church fiefs 'that all the evil customs owed their origin to the
reign of William Rufus'.8 And, even if they did, they were, it must be
remembered, distinctly abuses—'evil customs', as Henry I himself
terms them in his charter—namely (in the matter we are considering),
'excessive exactions in the way of reliefs, marriages and wardships,
debts to the crown, and forfeiture. In the place,' we are told, 'of
unlimited demands on these heads, the charter promises, not indeed
fixed amercements, but a return to ancient equitable custom'.9 All this
refers, it will be seen, to the abuse of an existing institution, not to
the introduction of a new one. The fact is that Ranulf's proceedings
have been assigned a quite exceptional and undue importance.
Broadly speaking, his actions fall under a law too often lost sight of,
namely, that when the crown was strong it pressed, through the
official bureaucracy, its claims to the uttermost; and when it found
itself weak, it renounced them so far as it was compelled. Take, for
instance, this very charter issued by Henry I, when he was 'playing to
the gallery', and seeking general support: what was the value of its
promises? They were broken, says Mr Freeman, to the Church;10 they
were probably broken, says Dr Stubbs, to the knights;11 and they
were certainly broken, I may add, to the unfortunate tenants-in-chief,
whom the Pipe-Roll of 1130 shows us suffering from those same
excessive exactions, of which the monopoly is assigned to Ranulf
Flambard, and which 'the Lion of Justice' had so virtuously renounced.
I might similarly adduce the exactions from the Church by that
excellent king, Henry II (1159), 'contra antiquum morem et debitam
libertatem'; but it is needless to multiply examples of the struggle
between the interests of the crown and those of its tenants-in-chief,
which was as fierce as ever when, in later days, it led to the
provisions of the Great Charter. What the barons, lay and spiritual,
complained of from first to last, was not the feudal system that
accompanied their military tenure, but the abuse of that system in the
excessive demands of the crown.
Here then the writer does not hesitate to base on a single accidental
notice the existence of an event quite as widespread and important as
the introduction of knight service.23
I have now endeavoured to make plain one of the chief flaws in the
view at present accepted, namely, that it is mainly grounded on the
negative evidence of Domesday, which evidence will not bear the
construction that has been placed upon it—and further that, even if it
did, we should be landed in a fresh difficulty, the gulf between
Domesday and Henry's charter being only to be bridged by the
assumption that Ranulf Flambard 'devised' and introduced military
tenure, with its results—an assumption, we have seen, which the facts
of the case not only fail to support, but even discountenance wholly.
Dr Stubbs, on the other hand, while rejecting the view that military
service, since the days of Alfred, had been practically fixed at one
warrior for every five hides,30 leans nevertheless to the belief that the
knight's fee was developed out of the five-hide unit, and that the
military 'service' of a tenant-in-chief was determined by the number of
such units which he possessed. But, as he also recognizes the £20
unit, there will be less danger of misrepresenting his views if I append
verbatim the relevant passages:
The
variation in
the number
of hides
contained in
the knight's
fee.36
The fourth and last criticism which I propose to offer on the subject is
this. If we find that under Henry II—when we meet with definite
information—a fief contained, as we might expect, more 'units of
possession' than it was bound to furnish knights (thus leaving a
balance over for the baro after sub-infeudation), we must draw one of
two conclusions: either this excess had existed from the first; or, if the
fief (as we are asked to believe) was originally assessed up to the hilt
for military service, that assessment must, in the interval, have been
reduced. In other words, Henry I—if, as Dr Stubbs in one place
suggests,39 he was the first to take a 'regular account of the knights'
fees'—must have found the land with a settled liability of providing
one knight for every five hides, and must, yet, have reduced that
liability of his own accord, on the most sweeping scale, thus, contrary
to all his principles, ultroneously deprived himself of the 'service' he
was entitled to claim.
Having completed my criticisms of the accepted view, and set forth its
chief difficulties, I shall now propound the theory to which my own
researches have led me, following the same method of proof as that
adopted by Mr Seebohm in his English Village Community, namely
working back from the known to the relatively unknown, till the light
thrown upwards by the records of the twelfth century illumines the
language of Domesday and renders the allusions of monks and
chroniclers pregnant with meaning.
Let me here break off for a moment to consider one of the most
important points suggested by this great inquest, namely, the issue of
the writs under which it was held. It has been generally assumed that
each tenant received his writ direct from the crown; and a casual
reading of the cartae might, perhaps, favour such a view. I have,
however, been led to the conclusion that a general writ was issued to
the sheriff of each county, and that its terms were communicated by
him to the several tenants-in-chief, whose capita baroniæ lay within
his jurisdiction.
Baderun of Monmouth has heard the writ read out in the county
court;45 Earl Patrick also has heard the writ read out.46 William fitz
Siward derives from the sheriff, he tells us, his knowledge of the
writ:47 even the bishop of Chester has received his instructions from
the sheriff.48 But more especially do I rely upon the return of the
Archbishop of York because he recites the tenor of the writ in terms
which can leave no doubt that it was addressed, through the sheriff,
to the whole shire collectively.49 If the Archbishop of York did not
receive a special writ, we may fairly infer that no other tenant can
have done so.
Returning now to the terms of the inquiry, it is obvious that the tenant
(baro) to whom such queries were addressed must of necessity have
belonged to one of these three classes—
Having made this point clear, I now pass to the immediate object of
the inquest of 1166. What that object was, no one has as yet
discovered. Dr Stubbs, for instance, in his preface to the Pipe-Roll of
1166, writes: 'On the immediate purpose for which the inquiry was
made—and it can scarcely be doubted that it was for the collection of
a scutage—we shall look for further information in the rolls of the
succeeding years.' My own researches enable me to assert that this
inquest formed part of a financial revolution hitherto ignored, which
deserves to be compared with those other innovations in
administration and finance that characterized the latter half of the
twelfth century in England.
When we come to place side by side the returns of 1166 and the
payments made upon those returns in 1168, we find (at least, on the
lay fiefs) the same distinction in both between 'the old feoffment' and
'the new'. But while the returns, as we saw, were made under three
heads,52 the payments were made under two, namely, under the two
feoffments. The reason of this difference can be established beyond
dispute: the exchequer clerks had, in every instance, added the
returns under the third head to those under the first, and classed
them together as 'old feoffment'. This is one of the points which, I
think, have never been hitherto explained.
Plenty of examples might be given, but these two will suffice. Walter
de Aincurt returns 24 fees de veteri, 5 de novo, and 11 super
dominium. The exchequer, in 1168, records him as paying on 35 fees
de veteri, and on 5 de novo.53 Richard de Haie returns 11 fees de
veteri, 4 de novo, and 5 super dominium. The exchequer records him
as paying on 16 de veteri, and 4 de novo.
The question may very fairly be asked, 'What check had the crown
upon a tenant in the event of the latter omitting some of his "excess"
fees?' The answer is supplied, I think, by a clause in the invaluable
return of the northern primate. He there requests that his return may
be accepted 'without prejudice', as a lawyer would say, in case of his
omitting some small fees. That is to say, these formal returns might
be brought up as evidence against tenants-in-chief who had omitted
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com