SlideShare a Scribd company logo
Android Apps Development
Md. Moniruzzaman
Sr. Software Engineer
W3 Engineers Ltd.
Date: 03-02-2018
 Overview of the Android App component(Activities, Services, Broadcast
receivers, Content providers)
 Android Platform Architecture
 Activity
 Fragment
 Android Layout
 Android Resource management
 Android animation
 RecyclerView
 Adapter
Agenda
After attending this session you are expected to be able to
 Create a android project
 Managing android resources
 Display category-wise/section-wise list of data
 Android animation
 Fragment management
Objectives
App components are the essential building blocks of an Android app. Each
component is an entry point through which the system or a user can enter your
app. Some components depend on others.
There are four different types of app components:
• Activities.
• Services.
• Broadcast receivers.
• Content providers.
Each type serves a distinct purpose and has a distinct lifecycle that defines how
the component is created and destroyed.
Android App component
Android is an open source, Linux-based software stack created for a wide array
of devices and form factors. The following diagram shows the major
components of the Android platform.
Android Platform Architecture
Figure : The Android software
stack
Activities are one of the fundamental building blocks of apps on the Android
platform. Skillfully managing activities allows you to ensure that, for example:
• Orientation changes take place smoothly without disrupting the user
experience.
• User data is not lost during activity transitions.
• The system kills processes when it's appropriate to do so.
Activities
As a user navigates through, the Activity instances in your app transition
through different states in their lifecycle. The Activity class provides a number
of callbacks that allow the activity to know that a state has changed.
Activity-lifecycle concepts: To navigate transitions between stages of the
activity lifecycle, the Activity class provides a core set of six
callbacks: onCreate(), onStart(), onResume(), onPause(), onStop(),
and onDestroy().
Continue…
The Activity Lifecycle
Activity-lifecycle concepts
public class MainActivity extends Activity {
String msg = "Android : ";
/** Called when the activity is first created. */
@Override
Public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/** Called when the activity is about to become visible. */
@Override
protected void onStart() {
super.onStart();
} Continue…
Activity Class
/** Called when the activity has become visible. */
@Override
protected void onResume() {
super.onResume();
}
/** Called when another activity is taking focus. */
@Override
protected void onPause() {
super.onPause();
}
}
Continue…
Activity Class
/** Called when the activity is no longer visible. */
@Override
protected void onStop() {
super.onStop();
Log.d(msg, "The onStop() event");
/** Called just before the activity is destroyed. */
@Override
public void onDestroy() {
super.onDestroy();
Log.d(msg, "The onDestroy() event");
}
}
Activity Class
An application can have one or more activities without any restrictions. Every
activity you define for your application must be declared in
your AndroidManifest.xml file and the main activity for your app must be
declared in the manifest with an <intent-filter> that includes the MAIN action
and LAUNCHER category .
If either the MAIN action or LAUNCHER category are not declared for one of
your activities, then your app icon will not appear in the Home screen's list of
apps.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.tutorialspoint7.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher“
android:label="@string/app_name"
android:supportsRtl="true“
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
AndroidManifest.xml
Figure: The lifecycle of a fragment (while its
activity is running).
Fragment-lifecycle
Design Philosophy
Android introduced fragments in Android 3.0 (API level 11), primarily to
support more dynamic and flexible UI designs on large screens, such as
tablets.
Figure 1. An example of how two UI modules defined
by fragments can be combined into one activity for a
tablet design, but separated for a handset design.
Adding a Fragment to an Activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment android:name="com.example.news.ArticleListFragment"
android:id="@+id/list"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent" />
<fragment android:name="com.example.news.ArticleReaderFragment"
android:id="@+id/viewer"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="match_parent" />
</LinearLayout>
Continue…
There are two ways you can add a fragment to the activity layout:
• Declare the fragment inside the activity's layout file.
Adding a Fragment to an Activity
At any time while your activity is running, you can add fragments to your activity
layout. You simply need to specify a ViewGroup in which to place the fragment.
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
You can then add a fragment using the add() method, specifying the fragment to add
and the view in which to insert it. For example:
ExampleFragment fragment = new ExampleFragment();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
• Or, programmatically add the fragment to an existing ViewGroup.
Adding a Fragment to an Activity
A great feature about using fragments in your activity is the ability to add,
remove, replace, and perform other actions with them, in response to user
interaction. Each set of changes that you commit to the activity is called a
transaction and you can perform one using APIs in FragmentTransaction.
For example, here's how you can replace one fragment with another, and
preserve the previous state in the back stack:
// Create new fragment and transaction
Fragment newFragment = new ExampleFragment();
FragmentTransaction transaction =
getSupportFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
A layout defines the visual structure for a user interface, such as the UI for
an activity or app widget. You can declare a layout in two ways:
• Declare UI elements in XML. Android provides a straightforward XML
vocabulary that corresponds to the View classes and subclasses, such as
those for widgets and layouts.
• Instantiate layout elements at runtime. Your application can create View and
ViewGroup objects (and manipulate their properties) programmatically.
Layouts
Figure: Visualization of a view hierarchy with layout parameters
associated with each view.
Layouts Parameters
XML layout attributes named layout_something define layout parameters for
the View that are appropriate for the ViewGroup in which it resides.
Layouts Types
There are different view layouts in an android mobile application. The six
different layouts are:
1. Linear Layout
2. Relative Layout
3. Table Layout
4. Frame Layout
5. Coordinator Layout
6. Constraint Layout
1. Linear Layout-
In a linear layout, like the name suggests, all the elements are displayed in a
linear fashion(below is an example of the linear layouts),
either Horizontally or Vertically and this behavior is set
in android:orientationwhich is an attribute of the node LinearLayout.
Example of Vertical layout snippet
<LinearLayout android:orientation="vertical"> .... </LinearLayout>
Example of Horizontal layout snippet
<LinearLayout android:orientation="horizontal"> .... </LinearLayout>
Continue…
Layouts Types
2. Relative Layout-
In a relative layout every element arranges itself relative to other elements or
a parent element.
As an example, lets consider the layout defined below. The “Cancel” button is
placed relatively, to the right ofthe “Login” button parallely. Here is the code
snippet that achieves the mentioned alignment (Right of Login button
parallely)
Example code snippet-
<Button android:id="@+id/btnLogin" ..></Button>
<Button android:layout_toRightOf="@id/btnLogin"
android:layout_alignTop="@id/btnLogin" ..></Button>
Continue…
Layouts Types
3. Table Layout-
Table layouts in Android works in the same way HTML table layouts work. You
can divide your layouts into rows and columns.
<TableLayout >
<TableRow > …….</TableRow>
<TableRow > …….</TableRow>
<TableRow > …….</TableRow>
</TableLayout >
4. FrameLayout - It behave as a single object and its child views are get
overlapped over each other. FrameLayout takes the size of as per the biggest
child element.
5. Coordinator Layout - This is the most powerful ViewGroup introduced in
Android support library. It behaves as FrameLayout and has a lot of
functionality to coordinates amongst its child views. e.g floating button and
snackbar, Toolbar with scrollable view.
Resources Overview
You should always externalize resources such as images and strings from your
application code, so that you can maintain them independently.
For any type of resource, you can specify default and
multiple alternative resources for your application:
• Default resources are those that should be used regardless of the device
configuration or when there are no alternative resources that match the
current configuration.
• Alternative resources are those that you've designed for use with a
specific configuration. To specify that a group of resources are for a
specific configuration, append an appropriate configuration qualifier to
the directory name.
Grouping Resource Types
You should place each type of resource in a specific subdirectory of your
project's res/ directory. For example, here's the file hierarchy for a simple
project:
MyProject/
src/
MyActivity.java
res/
drawable/
graphic.png
layout/
main.xml
info.xml
mipmap/
icon.png
values/
strings.xml
Android Animation
Adding animations to your app interface will give high quality feel to your
android applications. Animations can be performed through either XML or
android code.
There are 3 types of Animations:
Property Animations—They are used to alter property of objects (Views or
non view objects).
View Animations—They are used to do simple animations like changing size,
position, rotation, control transparency.
Drawable Animations—This is used to do animation using drawables. An XML
file specifying various list of drawables is made which are run one by one just
like a roll of a film. This is not much used so I won’t cover it.
Android Animation Using XML
Create an xml file which defines type of animation to perform. This file should
be located under anim folder under res directory (res ⇒ anim ⇒
animation.xml). If you don’t have anim folder in your res directory create one.
Following is example of simple fade in animation.
Android Animation Using XML
Create xml that defines the animation:
fade_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:toAlpha="1.0" />
</set>
Loading Animation
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fadein);
txtMessage = (TextView) findViewById(R.id.txtMessage);
// load the animation
Animation animFadein =
AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
}
Animation listeners (Optional)
public class FadeInActivity extends Activity implements AnimationListener {
animFadein.setAnimationListener(this);
@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
}
@Override
public void onAnimationRepeat(Animation animation) {
// Animation is repeating
}
@Override
public void onAnimationStart(Animation animation) {
// Animation started
}
}
Start the animation
You can start animation whenever you want by calling startAnimation on any
UI element by passing the type of animation. In this example i am calling fade
in animation on TextView:
// start the animation
txtMessage.startAnimation(animFadein);
However instead of xml we can also use android code to create animation such
like a class is ObjectAnimator
ObjectAnimator rotationAnimator =
ObjectAnimator.ofFloat(animateTextView, "rotation", 360f);
rotationAnimator.setDuration(2000);
Creating Lists and Cards
To create complex lists and cards with material design styles in your apps, you
can use the RecyclerView and CardView widgets.
Figure : The RecyclerView widget.
RecyclerView provides these built-in layout managers:
LinearLayoutManager shows items in a vertical or horizontal scrolling list.
GridLayoutManager shows items in a grid.
StaggeredGridLayoutManager shows items in a staggered grid.
To create a custom layout manager, extend
the RecyclerView.LayoutManager class.
RecyclerView
<!-- A RecyclerView with some commonly used attributes -->
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Once you have added a RecyclerView widget to your layout, obtain a handle
to the object, connect it to a layout manager, and attach an adapter for the
data to be displayed:
Continue…
RecyclerView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_activity);
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
// use a linear layout manager
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
// specify an adapter (see also next example)
mAdapter = new MyAdapter(myDataset);
mRecyclerView.setAdapter(mAdapter);
}
Adapter
The adapter provides access to the items in your data set, creates views for
items, and replaces the content of some of the views with new data items
when the original item is no longer visible.
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private String[] mDataset;
// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public static class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public TextView mTextView;
public ViewHolder(TextView v) {
super(v);
mTextView = v;
}
}
Continue…
Adapter
// Provide a suitable constructor (depends on the kind of dataset)
public MyAdapter(String[] myDataset) {
mDataset = myDataset;
}
// Create new views (invoked by the layout manager)
@Override
public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
// create a new view
TextView v = (TextView) LayoutInflater.from(parent.getContext())
.inflate(R.layout.my_text_view, parent, false);
// set the view's size, margins, paddings and layout parameters
...
ViewHolder vh = new ViewHolder(v);
return vh;
}
Continue…
Adapter
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
holder.mTextView.setText(mDataset[position]);
}
// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
return mDataset.length;
}
}
Different view in adapter
To handle the case where you want different types of view for different
rows. For instance, in a contacts application you may want even rows to have
pictures on the left side and odd rows to have pictures on the right. In that
case, you would use:
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public int getItemViewType(int position) {
return position % 2;
}
Continue…
Different view in adapter
@Override
public MainVH onCreateViewHolder(ViewGroup parent, int viewType) {
int layoutRes;
switch (viewType) {
case VIEW_TYPE_HEADER:
layoutRes = R.layout.item_header;
break;
case VIEW_TYPE_FOOTER:
layoutRes = R.layout.item_footer;
break;
default:
layoutRes = R.layout.content_swipe;
break;
}
View v = LayoutInflater.from(parent.getContext())
.inflate(layoutRes, parent, false);
return new MainVH(v);
}
Create Cards
CardView extends the FrameLayout class and lets you show information inside cards
that have a consistent look across the platform. CardView widgets can have
shadows and rounded corners.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
... >
<!-- A CardView that contains a TextView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="200dp"
android:layout_height="200dp"
card_view:cardCornerRadius="4dp">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
</LinearLayout>
Add Dependencies
The RecyclerView and CardView widgets are part of the v7 Support
Libraries. To use these widgets in your project, add these Gradle
dependencies to your app's module:
dependencies {
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+‘
}
 Showing section wise/category wise list of static data
 Each item must have image, title and details
 When click on a single item get details view of item
 Collapsing functionality on the details page
 Last date/time of submission
Assignment Details
 Android studio, SDK , Java.
 Recyclerview, Adapter, XML layout design, Animation
 For any help conduct with me or any android developer
Assignment Guidelines
• https://developer.android.com/guide/components/fundamentals.html#Co
mponents
• https://developer.android.com/guide/platform/index.html
• https://developer.android.com/guide/components/activities/activity-
lifecycle.html
• https://developer.android.com/guide/components/fragments.html
• https://developer.android.com/training/basics/fragments/creating.html
• https://developer.android.com/guide/topics/ui/declaring-layout.html
• https://developer.android.com/training/basics/fragments/fragment-ui.html
• https://developer.android.com/guide/topics/resources/providing-
resources.html#ResourceTypes
• https://www.androidhive.info/2013/06/android-working-with-xml-
animations/
• https://medium.com/mindorks/a-beginners-guide-to-implement-android-
animations-part-1-2-part-series-b5fce1fc85
• https://developer.android.com/training/material/lists-
cards.html#RecyclerView
Resources
Q & A
Thank You
Ad

More Related Content

What's hot (20)

Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
Headerlabs Infotech Pvt. Ltd.
 
Android UI
Android UIAndroid UI
Android UI
nationalmobileapps
 
Android layouts
Android layoutsAndroid layouts
Android layouts
Jeffrey Quevedo
 
Android components
Android componentsAndroid components
Android components
NAVEENA ESWARAN
 
Android Components
Android ComponentsAndroid Components
Android Components
Aatul Palandurkar
 
Android Screen Containers & Layouts
Android Screen Containers & LayoutsAndroid Screen Containers & Layouts
Android Screen Containers & Layouts
Vijay Rastogi
 
Chapt 04 user interaction
Chapt 04 user interactionChapt 04 user interaction
Chapt 04 user interaction
Edi Faizal
 
Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen Widgets
Richard Hyndman
 
Unit2
Unit2Unit2
Unit2
DevaKumari Vijay
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)
Khaled Anaqwa
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
Siva Kumar reddy Vasipally
 
Android xml-based layouts-chapter5
Android xml-based layouts-chapter5Android xml-based layouts-chapter5
Android xml-based layouts-chapter5
Dr. Ramkumar Lakshminarayanan
 
Android Tutorial
Android TutorialAndroid Tutorial
Android Tutorial
Fun2Do Labs
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & Intents
Lope Emano
 
A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter component
Katy Slemon
 
Android UI Patterns
Android UI PatternsAndroid UI Patterns
Android UI Patterns
Peter Pascale
 
Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intent
Diego Grancini
 
MVC
MVCMVC
MVC
Ravi Bansal
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
Ahsanul Karim
 
Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_android
Denis Minja
 
Android Screen Containers & Layouts
Android Screen Containers & LayoutsAndroid Screen Containers & Layouts
Android Screen Containers & Layouts
Vijay Rastogi
 
Chapt 04 user interaction
Chapt 04 user interactionChapt 04 user interaction
Chapt 04 user interaction
Edi Faizal
 
Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen Widgets
Richard Hyndman
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)
Khaled Anaqwa
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
Siva Kumar reddy Vasipally
 
Android Tutorial
Android TutorialAndroid Tutorial
Android Tutorial
Fun2Do Labs
 
Android development - Activities, Views & Intents
Android development - Activities, Views & IntentsAndroid development - Activities, Views & Intents
Android development - Activities, Views & Intents
Lope Emano
 
A comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter componentA comprehensive guide on developing responsive and common react filter component
A comprehensive guide on developing responsive and common react filter component
Katy Slemon
 
Android App Development - 02 Activity and intent
Android App Development - 02 Activity and intentAndroid App Development - 02 Activity and intent
Android App Development - 02 Activity and intent
Diego Grancini
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
Ahsanul Karim
 
Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_android
Denis Minja
 

Similar to Android apps development (20)

Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
Gil Irizarry
 
mobile application development -unit-3-
mobile application development  -unit-3-mobile application development  -unit-3-
mobile application development -unit-3-
TejamFandat
 
Android Apps Development Basic
Android Apps Development BasicAndroid Apps Development Basic
Android Apps Development Basic
Monir Zzaman
 
Hello Android
Hello AndroidHello Android
Hello Android
Trong Dinh
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2
Tadas Jurelevičius
 
Android training day 2
Android training day 2Android training day 2
Android training day 2
Vivek Bhusal
 
Activity
ActivityActivity
Activity
NikithaNag
 
Activity
ActivityActivity
Activity
NikithaNag
 
Activity
ActivityActivity
Activity
roopa_slide
 
Activity
ActivityActivity
Activity
roopa_slide
 
Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1
Amit Saxena
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
Aly Abdelkareem
 
07_UIAndroid.pdf
07_UIAndroid.pdf07_UIAndroid.pdf
07_UIAndroid.pdf
ImranS18
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
maamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
maamir farooq
 
Android ui with xml
Android ui with xmlAndroid ui with xml
Android ui with xml
Egerton University
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
Ahsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
Ahsanul Karim
 
Android application componenets for android app development
Android application componenets for android app developmentAndroid application componenets for android app development
Android application componenets for android app development
BalewKassie
 
Android 3
Android 3Android 3
Android 3
Robert Cooper
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
Gil Irizarry
 
mobile application development -unit-3-
mobile application development  -unit-3-mobile application development  -unit-3-
mobile application development -unit-3-
TejamFandat
 
Android Apps Development Basic
Android Apps Development BasicAndroid Apps Development Basic
Android Apps Development Basic
Monir Zzaman
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2
Tadas Jurelevičius
 
Android training day 2
Android training day 2Android training day 2
Android training day 2
Vivek Bhusal
 
Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1
Amit Saxena
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
Aly Abdelkareem
 
07_UIAndroid.pdf
07_UIAndroid.pdf07_UIAndroid.pdf
07_UIAndroid.pdf
ImranS18
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
maamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
maamir farooq
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
Ahsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
Ahsanul Karim
 
Android application componenets for android app development
Android application componenets for android app developmentAndroid application componenets for android app development
Android application componenets for android app development
BalewKassie
 
Ad

Recently uploaded (20)

Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Exceptional Behaviors: How Frequently Are They Tested? (AST 2025)
Andre Hora
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)Who Watches the Watchmen (SciFiDevCon 2025)
Who Watches the Watchmen (SciFiDevCon 2025)
Allon Mureinik
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Maxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINKMaxon CINEMA 4D 2025 Crack FREE Download LINK
Maxon CINEMA 4D 2025 Crack FREE Download LINK
younisnoman75
 
Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025Adobe Master Collection CC Crack Advance Version 2025
Adobe Master Collection CC Crack Advance Version 2025
kashifyounis067
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Exploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the FutureExploring Wayland: A Modern Display Server for the Future
Exploring Wayland: A Modern Display Server for the Future
ICS
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Ad

Android apps development

  • 1. Android Apps Development Md. Moniruzzaman Sr. Software Engineer W3 Engineers Ltd. Date: 03-02-2018
  • 2.  Overview of the Android App component(Activities, Services, Broadcast receivers, Content providers)  Android Platform Architecture  Activity  Fragment  Android Layout  Android Resource management  Android animation  RecyclerView  Adapter Agenda
  • 3. After attending this session you are expected to be able to  Create a android project  Managing android resources  Display category-wise/section-wise list of data  Android animation  Fragment management Objectives
  • 4. App components are the essential building blocks of an Android app. Each component is an entry point through which the system or a user can enter your app. Some components depend on others. There are four different types of app components: • Activities. • Services. • Broadcast receivers. • Content providers. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed. Android App component
  • 5. Android is an open source, Linux-based software stack created for a wide array of devices and form factors. The following diagram shows the major components of the Android platform. Android Platform Architecture Figure : The Android software stack
  • 6. Activities are one of the fundamental building blocks of apps on the Android platform. Skillfully managing activities allows you to ensure that, for example: • Orientation changes take place smoothly without disrupting the user experience. • User data is not lost during activity transitions. • The system kills processes when it's appropriate to do so. Activities
  • 7. As a user navigates through, the Activity instances in your app transition through different states in their lifecycle. The Activity class provides a number of callbacks that allow the activity to know that a state has changed. Activity-lifecycle concepts: To navigate transitions between stages of the activity lifecycle, the Activity class provides a core set of six callbacks: onCreate(), onStart(), onResume(), onPause(), onStop(), and onDestroy(). Continue… The Activity Lifecycle
  • 9. public class MainActivity extends Activity { String msg = "Android : "; /** Called when the activity is first created. */ @Override Public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } /** Called when the activity is about to become visible. */ @Override protected void onStart() { super.onStart(); } Continue… Activity Class
  • 10. /** Called when the activity has become visible. */ @Override protected void onResume() { super.onResume(); } /** Called when another activity is taking focus. */ @Override protected void onPause() { super.onPause(); } } Continue… Activity Class
  • 11. /** Called when the activity is no longer visible. */ @Override protected void onStop() { super.onStop(); Log.d(msg, "The onStop() event"); /** Called just before the activity is destroyed. */ @Override public void onDestroy() { super.onDestroy(); Log.d(msg, "The onDestroy() event"); } } Activity Class
  • 12. An application can have one or more activities without any restrictions. Every activity you define for your application must be declared in your AndroidManifest.xml file and the main activity for your app must be declared in the manifest with an <intent-filter> that includes the MAIN action and LAUNCHER category . If either the MAIN action or LAUNCHER category are not declared for one of your activities, then your app icon will not appear in the Home screen's list of apps. AndroidManifest.xml
  • 14. Figure: The lifecycle of a fragment (while its activity is running). Fragment-lifecycle
  • 15. Design Philosophy Android introduced fragments in Android 3.0 (API level 11), primarily to support more dynamic and flexible UI designs on large screens, such as tablets. Figure 1. An example of how two UI modules defined by fragments can be combined into one activity for a tablet design, but separated for a handset design.
  • 16. Adding a Fragment to an Activity <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment android:name="com.example.news.ArticleListFragment" android:id="@+id/list" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" /> <fragment android:name="com.example.news.ArticleReaderFragment" android:id="@+id/viewer" android:layout_weight="2" android:layout_width="0dp" android:layout_height="match_parent" /> </LinearLayout> Continue… There are two ways you can add a fragment to the activity layout: • Declare the fragment inside the activity's layout file.
  • 17. Adding a Fragment to an Activity At any time while your activity is running, you can add fragments to your activity layout. You simply need to specify a ViewGroup in which to place the fragment. FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); You can then add a fragment using the add() method, specifying the fragment to add and the view in which to insert it. For example: ExampleFragment fragment = new ExampleFragment(); fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit(); • Or, programmatically add the fragment to an existing ViewGroup.
  • 18. Adding a Fragment to an Activity A great feature about using fragments in your activity is the ability to add, remove, replace, and perform other actions with them, in response to user interaction. Each set of changes that you commit to the activity is called a transaction and you can perform one using APIs in FragmentTransaction. For example, here's how you can replace one fragment with another, and preserve the previous state in the back stack: // Create new fragment and transaction Fragment newFragment = new ExampleFragment(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit();
  • 19. A layout defines the visual structure for a user interface, such as the UI for an activity or app widget. You can declare a layout in two ways: • Declare UI elements in XML. Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts. • Instantiate layout elements at runtime. Your application can create View and ViewGroup objects (and manipulate their properties) programmatically. Layouts
  • 20. Figure: Visualization of a view hierarchy with layout parameters associated with each view. Layouts Parameters XML layout attributes named layout_something define layout parameters for the View that are appropriate for the ViewGroup in which it resides.
  • 21. Layouts Types There are different view layouts in an android mobile application. The six different layouts are: 1. Linear Layout 2. Relative Layout 3. Table Layout 4. Frame Layout 5. Coordinator Layout 6. Constraint Layout 1. Linear Layout- In a linear layout, like the name suggests, all the elements are displayed in a linear fashion(below is an example of the linear layouts), either Horizontally or Vertically and this behavior is set in android:orientationwhich is an attribute of the node LinearLayout. Example of Vertical layout snippet <LinearLayout android:orientation="vertical"> .... </LinearLayout> Example of Horizontal layout snippet <LinearLayout android:orientation="horizontal"> .... </LinearLayout> Continue…
  • 22. Layouts Types 2. Relative Layout- In a relative layout every element arranges itself relative to other elements or a parent element. As an example, lets consider the layout defined below. The “Cancel” button is placed relatively, to the right ofthe “Login” button parallely. Here is the code snippet that achieves the mentioned alignment (Right of Login button parallely) Example code snippet- <Button android:id="@+id/btnLogin" ..></Button> <Button android:layout_toRightOf="@id/btnLogin" android:layout_alignTop="@id/btnLogin" ..></Button> Continue…
  • 23. Layouts Types 3. Table Layout- Table layouts in Android works in the same way HTML table layouts work. You can divide your layouts into rows and columns. <TableLayout > <TableRow > …….</TableRow> <TableRow > …….</TableRow> <TableRow > …….</TableRow> </TableLayout > 4. FrameLayout - It behave as a single object and its child views are get overlapped over each other. FrameLayout takes the size of as per the biggest child element. 5. Coordinator Layout - This is the most powerful ViewGroup introduced in Android support library. It behaves as FrameLayout and has a lot of functionality to coordinates amongst its child views. e.g floating button and snackbar, Toolbar with scrollable view.
  • 24. Resources Overview You should always externalize resources such as images and strings from your application code, so that you can maintain them independently. For any type of resource, you can specify default and multiple alternative resources for your application: • Default resources are those that should be used regardless of the device configuration or when there are no alternative resources that match the current configuration. • Alternative resources are those that you've designed for use with a specific configuration. To specify that a group of resources are for a specific configuration, append an appropriate configuration qualifier to the directory name.
  • 25. Grouping Resource Types You should place each type of resource in a specific subdirectory of your project's res/ directory. For example, here's the file hierarchy for a simple project: MyProject/ src/ MyActivity.java res/ drawable/ graphic.png layout/ main.xml info.xml mipmap/ icon.png values/ strings.xml
  • 26. Android Animation Adding animations to your app interface will give high quality feel to your android applications. Animations can be performed through either XML or android code. There are 3 types of Animations: Property Animations—They are used to alter property of objects (Views or non view objects). View Animations—They are used to do simple animations like changing size, position, rotation, control transparency. Drawable Animations—This is used to do animation using drawables. An XML file specifying various list of drawables is made which are run one by one just like a roll of a film. This is not much used so I won’t cover it.
  • 27. Android Animation Using XML Create an xml file which defines type of animation to perform. This file should be located under anim folder under res directory (res ⇒ anim ⇒ animation.xml). If you don’t have anim folder in your res directory create one. Following is example of simple fade in animation.
  • 28. Android Animation Using XML Create xml that defines the animation: fade_in.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" > <alpha android:duration="1000" android:fromAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:toAlpha="1.0" /> </set>
  • 29. Loading Animation @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fadein); txtMessage = (TextView) findViewById(R.id.txtMessage); // load the animation Animation animFadein = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_in); }
  • 30. Animation listeners (Optional) public class FadeInActivity extends Activity implements AnimationListener { animFadein.setAnimationListener(this); @Override public void onAnimationEnd(Animation animation) { // Take any action after completing the animation } @Override public void onAnimationRepeat(Animation animation) { // Animation is repeating } @Override public void onAnimationStart(Animation animation) { // Animation started } }
  • 31. Start the animation You can start animation whenever you want by calling startAnimation on any UI element by passing the type of animation. In this example i am calling fade in animation on TextView: // start the animation txtMessage.startAnimation(animFadein); However instead of xml we can also use android code to create animation such like a class is ObjectAnimator ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(animateTextView, "rotation", 360f); rotationAnimator.setDuration(2000);
  • 32. Creating Lists and Cards To create complex lists and cards with material design styles in your apps, you can use the RecyclerView and CardView widgets. Figure : The RecyclerView widget. RecyclerView provides these built-in layout managers: LinearLayoutManager shows items in a vertical or horizontal scrolling list. GridLayoutManager shows items in a grid. StaggeredGridLayoutManager shows items in a staggered grid. To create a custom layout manager, extend the RecyclerView.LayoutManager class.
  • 33. RecyclerView <!-- A RecyclerView with some commonly used attributes --> <android.support.v7.widget.RecyclerView android:id="@+id/my_recycler_view" android:scrollbars="vertical" android:layout_width="match_parent" android:layout_height="match_parent"/> Once you have added a RecyclerView widget to your layout, obtain a handle to the object, connect it to a layout manager, and attach an adapter for the data to be displayed: Continue…
  • 34. RecyclerView @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_activity); mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(mLayoutManager); // specify an adapter (see also next example) mAdapter = new MyAdapter(myDataset); mRecyclerView.setAdapter(mAdapter); }
  • 35. Adapter The adapter provides access to the items in your data set, creates views for items, and replaces the content of some of the views with new data items when the original item is no longer visible. public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { private String[] mDataset; // Provide a reference to the views for each data item // Complex data items may need more than one view per item, and // you provide access to all the views for a data item in a view holder public static class ViewHolder extends RecyclerView.ViewHolder { // each data item is just a string in this case public TextView mTextView; public ViewHolder(TextView v) { super(v); mTextView = v; } } Continue…
  • 36. Adapter // Provide a suitable constructor (depends on the kind of dataset) public MyAdapter(String[] myDataset) { mDataset = myDataset; } // Create new views (invoked by the layout manager) @Override public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // create a new view TextView v = (TextView) LayoutInflater.from(parent.getContext()) .inflate(R.layout.my_text_view, parent, false); // set the view's size, margins, paddings and layout parameters ... ViewHolder vh = new ViewHolder(v); return vh; } Continue…
  • 37. Adapter // Replace the contents of a view (invoked by the layout manager) @Override public void onBindViewHolder(ViewHolder holder, int position) { // - get element from your dataset at this position // - replace the contents of the view with that element holder.mTextView.setText(mDataset[position]); } // Return the size of your dataset (invoked by the layout manager) @Override public int getItemCount() { return mDataset.length; } }
  • 38. Different view in adapter To handle the case where you want different types of view for different rows. For instance, in a contacts application you may want even rows to have pictures on the left side and odd rows to have pictures on the right. In that case, you would use: @Override public int getViewTypeCount() { return 2; } @Override public int getItemViewType(int position) { return position % 2; } Continue…
  • 39. Different view in adapter @Override public MainVH onCreateViewHolder(ViewGroup parent, int viewType) { int layoutRes; switch (viewType) { case VIEW_TYPE_HEADER: layoutRes = R.layout.item_header; break; case VIEW_TYPE_FOOTER: layoutRes = R.layout.item_footer; break; default: layoutRes = R.layout.content_swipe; break; } View v = LayoutInflater.from(parent.getContext()) .inflate(layoutRes, parent, false); return new MainVH(v); }
  • 40. Create Cards CardView extends the FrameLayout class and lets you show information inside cards that have a consistent look across the platform. CardView widgets can have shadows and rounded corners. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:card_view="http://schemas.android.com/apk/res-auto" ... > <!-- A CardView that contains a TextView --> <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="200dp" android:layout_height="200dp" card_view:cardCornerRadius="4dp"> <TextView android:id="@+id/info_text" android:layout_width="match_parent" android:layout_height="match_parent" /> </android.support.v7.widget.CardView> </LinearLayout>
  • 41. Add Dependencies The RecyclerView and CardView widgets are part of the v7 Support Libraries. To use these widgets in your project, add these Gradle dependencies to your app's module: dependencies { compile 'com.android.support:cardview-v7:21.0.+' compile 'com.android.support:recyclerview-v7:21.0.+‘ }
  • 42.  Showing section wise/category wise list of static data  Each item must have image, title and details  When click on a single item get details view of item  Collapsing functionality on the details page  Last date/time of submission Assignment Details
  • 43.  Android studio, SDK , Java.  Recyclerview, Adapter, XML layout design, Animation  For any help conduct with me or any android developer Assignment Guidelines
  • 44. • https://developer.android.com/guide/components/fundamentals.html#Co mponents • https://developer.android.com/guide/platform/index.html • https://developer.android.com/guide/components/activities/activity- lifecycle.html • https://developer.android.com/guide/components/fragments.html • https://developer.android.com/training/basics/fragments/creating.html • https://developer.android.com/guide/topics/ui/declaring-layout.html • https://developer.android.com/training/basics/fragments/fragment-ui.html • https://developer.android.com/guide/topics/resources/providing- resources.html#ResourceTypes • https://www.androidhive.info/2013/06/android-working-with-xml- animations/ • https://medium.com/mindorks/a-beginners-guide-to-implement-android- animations-part-1-2-part-series-b5fce1fc85 • https://developer.android.com/training/material/lists- cards.html#RecyclerView Resources
  • 45. Q & A

Editor's Notes

  • #27: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #28: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #29: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #30: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #31: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #32: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #33: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #34: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #35: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #36: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #37: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #38: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #39: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #40: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #41: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.
  • #42: Android 5.0 introduced various other animations — Reveal Effect, Activity/Fragment transitions, Shared Element transitions etc. Click here to learn more about this.