How Inflation Works!. Examine the following code public class MainActivity extends Activity public void onCreate(Bundle savedInstanceState)

Slides:



Advertisements
Similar presentations
JavaScript Part 6. Calling JavaScript functions on an event JavaScript doesn’t have a main function like other programming languages but we can imitate.
Advertisements

All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
1 Javascrbipt Intro Javascript (or js) is a programming language. Interpreted, not compiled. Not the same as java, but, similar. Use tags to use. Object-oriented.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
AJAX (Asynchronous JavaScript and XML) Amit Jain CS 590 – Winter 2008.
Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
Fluency with Information Technology INFO100 and CSE100 Katherine Deibel Katherine Deibel, Fluency in Information Technology1.
JS: Document Object Model (DOM)
Programming Concepts. Derive a new class from Activity of the framework Prepare the data beforehand, e.g., vertices, colours, normal vectors, texture.
Android Activities 1. What are Android Activities? Activities are like windows in an Android application An application can have any number of activities.
Cosc 5/4730 Introduction: Threads, Android Activities, and MVC.
More Basic HTML. Add spacing (single & double space) Save Refresh Add horizontal rule Add comments Add styles Add headings Add features Add alignments.
The DOM tree CS The DOM tree CS380 2 Types of DOM nodes  element nodes (HTML tag)  can have children and/or attributes  text nodes (text in.
Mobile Programming Lecture 6
JavaScript – The DOM JavaScript is object based The browser is object based – We can access the browser's objects in the same way we did JavaScript's Two.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
Threads and Services. Background Processes One of the key differences between Android and iPhone is the ability to run things in the background on Android.
HTML | DOM. Objectives  HTML – Hypertext Markup Language  Sematic markup  Common tags/elements  Document Object Model (DOM)  Work on page | HTML.
Lec.10 + (Chapter 8 & 9) GUI Java Applet Jiang (Jen) ZHENG July 6 th, 2005.
CSE 154 Lecture 20: The DoM tree.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Android Boot Camp Demo Application – Part 1. Development Environment Set Up Download and install Java Development Kit (JDK) Download and unzip Android.
Unleash the Power of jQuery Learning & Development Team Telerik Software Academy.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
Set 2: DOM IT452 Advanced Web and Internet Systems.
Advanced DOM Builds on last presentation on DOM Allows you to dynamically create elements and position them on a page DOM methods/properties are W3C standard.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
CSS Cascading Style Sheets A very brief introduction CSS, Cascading Style Sheets1.
Ajax and the GWT. Ajax  Asynchronous JavaScript And XML  Technology behind interactive web sites  Provide smoother experience than conventional web.
Activities and Intents Richard S. Stansbury 2015.
Advanced DOM Builds on last presentation on DOM Allows you to dynamically create elements and position them on a page DOM methods/properties are W3C standard.
HTML and the DOM. What is HTML? Hypertext Interconnected documents Markup Our code goes around our documents Language Yes, it’s programming.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, February 19, 2014 Session 4: JavaScript.
JS: Document Object Model (DOM) DOM stands for Document Object Model, and allows programmers generic access to: DOM stands for Document Object Model, and.
TCS Internal Maps. 2 TCS Internal Objective Objective :  MAPS o Integration of Maps.
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
Lecture 4: Sensors Topics: Motion, Position, and Environmental Sensors Date: Feb 11, 2016.
HTML HTML stands for Hyper Text Markup Language. HTML is used in making the base of a Website You can just use an online website maker like weebly.com.
How to build a Web Page or “The things geeks never told you!”
JQUERY AND AJAX
CSE 154 LECTURE 9: THE DOM TREE. The DOM tree The elements of a page are nested into a tree-like structure of objects the DOM has properties and methods.
XML DOM Week 11 Web site:
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
XML & JSON. Background XML and JSON are to standard, textual data formats for representing arbitrary data – XML stands for “eXtensible Markup Language”
CSCI 3100 Tutorial 5 JavaScript & Ajax Jichuan Zeng Department of Computer Science and Engineering The Chinese University of Hong.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Introduction to android
Programming Web Pages with JavaScript
UNIT 11 로봇 전화번호부 3/4 로봇 SW 콘텐츠 교육원 조용수.
GUI Programming Fundamentals
Android – Event Handling
Mobile Application Development BSCS-7 Lecture # 6
ITEC535 – Mobile Programming
Android Programming Lecture 6
CIS 470 Mobile App Development
Week 11 Web site: XML DOM Week 11 Web site:
Adding Functionality to the App Tip Calculator App Activity and the Activity Lifecycle onCreate is called by the system when an Activity.
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
Activities and Intents
CIS 470 Mobile App Development
Adding Components to Activity
CMPE419 Mobile Application Development
Activities, Fragments, and Intents
Android Sensor Programming
Presentation transcript:

How Inflation Works!

Examine the following code public class MainActivity extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); }

This is what happens when you don’t call setContentView()

Examine the following code public class MainActivity extends Activity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); }

Result when calling setContentView()

What is setContentView() public void setContentView(int layoutResID) { if (mContentParent == null) { installDecor(); } else { mContentParent.removeAllViews(); } mLayoutInflater.inflate(layoutResID, mContentParent); final Callback cb = getCallback(); if (cb != null && !isDestroyed()) { cb.onContentChanged(); } Taken from PhoneWindow.java

What is setContentView() public void setContentView(int layoutResID) { if (mContentParent == null) { installDecor(); } else { mContentParent.removeAllViews(); } mLayoutInflater.inflate(layoutResID, mContentParent); final Callback cb = getCallback(); if (cb != null && !isDestroyed()) { cb.onContentChanged(); } 1 Passing in specified layout resource to LayoutInflater.inflate()

Inflation?? Inflation happens when you instantiate an XML layout resource file into its corresponding View objects.

Let’s try explaining inflation with HTML Let's explain how Inflation works!

In the background, we have the DOM Let's explain how Inflation works! html body p DOM Tree

DOM Refresh The DOM is a tree of node objects representing an HTML document. The DOM is not actual HTML markup, it is javascript node Objects.

How to add this HTML Snippet into the ? I am some text that will be inflated Imagine this HTML is stored in a separate file called snippet.html We want to take this snippet and somehow add it into the DOM

html body p I am some text that will be inflated A naive attempt. Directly add HTML to DOM nodes.

html body p I am some text that will be inflated A naive attempt. Directly add HTML to DOM nodes. BAD!!!

Convert HTML to node I am some text that will be inflated //create a new node var div = document.createElement("div"); //set background color of to red div.style.backgroundColor = "red"; //create a node var p = document.createElement("p"); p.innerHTML = "I am some text that will be inflated"; //find var body = document.getElementByTagName("body")[0]; //attach to div.appendChild(p); //attach to body.appendChild(div);

Convert HTML to node //create a new node var div = document.createElement("div"); //set background color of to red div.style.backgroundColor = "red"; //create a node var p = document.createElement("p"); p.innerHTML = "I am some text that will be inflated"; //find var body = document.getElementByTagName("body")[0]; //attach to div.appendChild(p); //attach to body.appendChild(div);

Convert HTML to node //create a new node var div = document.createElement("div"); //set background color of to red div.style.backgroundColor = "red"; //create a node var p = document.createElement("p"); p.innerHTML = "I am some text that will be inflated"; //find var body = document.getElementByTagName("body")[0]; //attach to div.appendChild(p); //attach to body.appendChild(div);

Convert HTML to node //create a new node var div = document.createElement("div"); //set background color of to red div.style.backgroundColor = "red"; //create a node var p = document.createElement("p"); p.innerHTML = "I am some text that will be inflated"; //find var body = document.getElementByTagName("body")[0]; //attach to div.appendChild(p); //attach to body.appendChild(div); bg-color: red

Convert HTML to node //create a new node var div = document.createElement("div"); //set background color of to red div.style.backgroundColor = "red"; //create a node var p = document.createElement("p"); p.innerHTML = "I am some text that will be inflated"; //find var body = document.getElementByTagName("body")[0]; //attach to div.appendChild(p); //attach to body.appendChild(div); bg-color: red

Convert HTML to node //create a new node var div = document.createElement("div"); //set background color of to red div.style.backgroundColor = "red"; //create a node var p = document.createElement("p"); p.innerHTML = "I am some text that will be inflated"; //find var body = document.getElementByTagName("body")[0]; //attach to div.appendChild(p); //attach to body.appendChild(div); bg-color: red #text: I am…

Convert HTML to node //create a new node var div = document.createElement("div"); //set background color of to red div.style.backgroundColor = "red"; //create a node var p = document.createElement("p"); p.innerHTML = "I am some text that will be inflated"; //find var body = document.getElementByTagName("body")[0]; //attach to div.appendChild(p); //attach to body.appendChild(div); bg-color: red #text: I am…

Convert HTML to node //create a new node var div = document.createElement("div"); //set background color of to red div.style.backgroundColor = "red"; //create a node var p = document.createElement("p"); p.innerHTML = "I am some text that will be inflated"; //find var body = document.getElementByTagName("body")[0]; //attach to div.appendChild(p); //attach to body.appendChild(div); bg-color: red #text: I am…

Inflation: Going from HTML to Node Object I am some text that will be inflated snippet.html Inflater Machine

Objects Inflation: Going from HTML to Node Object I am some text that will be inflated snippet.html HTMLHTML Inflater Machine bg-color: red #text: I am…

Bringing it all together html body p bg-color: red #text: I am…

Let's explain how Inflation works! I am some text that will be inflated html body p bg-color: red #text: I am…

((Activity)context).getLayoutInflater().inflate(R.layout.rating_text_view, this); In Android World