Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Building Android UIs with Custom Views

You're reading from   Building Android UIs with Custom Views Build amazing custom user interfaces with Android custom views

Arrow left icon
Product type Paperback
Published in Oct 2017
Publisher Packt
ISBN-13 9781785882869
Length 294 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Raimon Ràfols Montane Raimon Ràfols Montane
Author Profile Icon Raimon Ràfols Montane
Raimon Ràfols Montane
Arrow right icon
View More author details
Toc

Instantiating custom views

Now that we've seen how to set parameters on the XML layout and parse them on our custom view class, we'll see how to instantiate custom views from code as well and reuse then as much as possible from both instantiation mechanisms.

Instantiating custom views from code

On our custom view, we've created a single constructor with two parameters, a Context and an AttributeSet. Now, if we're creating our UI programmatically, or if by any other reason we need to instantiate our custom view by code, we need to create an additional constructor.

As we want to keep using our custom view in our XML layouts, we have to keep both constructors. To code avoid duplication, we will create some...

You have been reading a chapter from
Building Android UIs with Custom Views
Published in: Oct 2017
Publisher: Packt
ISBN-13: 9781785882869
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime