If you can't read please download the document
Upload
vivek-bhusal
View
1.613
Download
0
Embed Size (px)
Citation preview
Android Apps Development TrainingDay - 2
XML
Android's defined tags
Used to define some of the resources:Layouts
Strings
Android Manifest
Preferred way for defining UI elements:Separation of code
R class
Auto-generated: DO NOT EDIT
Contains ID of the project resources
Use findViewById and Resources object to get access to the resources:E.g. Button = (Button)findViewById(R.id.button);
E.g. getResources().getString(R.string.hello);
Layout
Eclipse has a great UI creatorGenerates all the XML for you !
Composed of View objects
Can be specified for portrait or landscapeDifferent designs for different orientation.
Contd.
A layout/activity is composed of Views and ViewGroups.
View is something that is visible.
Examples:TextViews, Buttons, TimePicker, DatePicker
Contd.
Button
There are 3 ways to declaring width and height:a. fill_parentb. wrap_contentc. match_parentDo not forgetto define us :)
Contd.
EditText
You can change the type of inputs as necessary
Contd.
TextView
Visibility types:a. visibleb. invisiblec. gone
Contd.
ViewGroups are the building blocks to Views:This is the to your View
One or more View can be grouped into a ViewGroup
Types to ViewGroups:LinearLayout*
RelativeLayout*
FrameLayout
TableLayout
ScrollView*, etc.
Each layout has something unique to it
Each layout has a purpose !
LinearLayout
(TextViews, Buttons etc.)
Declaring the XMLnamespace(done in the 1st ViewGroup)Unique for this ViewGroupa. verticalb. horizontal
RelativeLayout
Does not have any android:orientation.
Affects the layouts inside it.
Views are arranged according to references.
Contd.
Various other positioning techniques also there:alignLeftalignBaseLineabove, etc.
LinearLayout VS. RelativeLayout
LinearLayout RelativeLayout
Lets Unite !
You can use Viewgroups within Viewgroups : LAYOUTCEPTION !
Building a simple UI
Redirect to another page with all the filled details
What is needed for this?
Intentspage 2
Intent = Redirecting !
But wait
Intent is used to call into android's drivers, other applications as well.
Powerful inter/intra application message-passing framework.
Modification in the Android Manifest:
Declares an activity (an Activity subclass) that implements part of the application's visual user interface. The types of intents that an app can respond toAdds a category name to an intent filterAdds an action to an intent filter.
Confused ? Don't worry !
Remeber this ?
In your main class:Intent i = new Intent(MainActivity.this, ClassName.class); // Instantiating the intent classi.putExtra(name, value); // values to be sentstartActivity(i); // Starting the intent
Another class:Intent i = getIntent(); //getting the intent objectString name = i.getStringExtra(name); //getting value from passed intent
Explaining it all
Create your form UI interface
Result interface
Create two classes that extend the UIFormClass?
ResultClass?
Add your ResultClass to the Android Manifest.
Pass data from your FormClass to ResultClass using intents.
What is Manifest ?
Presents essential information about:The application to the Android systemInformation the system must have before it can run any of the application's code.
Remember this ?
Name of the Java package for the application.
It describes the components of the application the activities, services, broadcast receivers, and content providers.
It determines which processes will host application components.
It declares which permissions the application must have in order to access protected parts of the API and interact with other applications.
It also declares the permissions that others are required to have in order to interact with the application's components.
It lists the Instrumentation classes that provide profiling and other information as the application is running. These declarations are present in the manifest only while the application is being developed and tested; they're removed before the application is published.
It declares the minimum level of the Android API that the application requires.
It lists the libraries that the application must be linked against.
Have you ever wondered what happens when you press the back button/ home button on android?
Activity Life Cycle