Android Application
Development Session-2
From Beginner to Advanced
By : Ahesanali Suthar
email:ahesanali.suthar@gmail.com
Topics Covered
1.

Android Framework (Activity,Service,Broadcastreceiver,Content Providers)

2.

Android Layout

3.

Basic UI Widgets (Button,TextBox,Choice Box)
1. Android Framework
●

Android App framework have four basic components which are listed
below
1.
2.

Service.

3.

Broadcast Receiver.

4.
●

Activity.

Content Providers

We will see each component in small detail
1. Android Framework
1.

Activity:
● An Activity is an application component that provides a screen with
which users can interact in order to do something, such as dial the
phone, take a photo, send an email, or view a map
●

Each activity is given a window in which to draw its user interface.
The window typically fills the screen.

●

Activity handle events in short for a windows .NET programer Activity
is a code that is generated when we place button in form and double
click on it and Visual Studio IDE generate button1_click() method or
function.

●

Activity decides which Screen(in android terminology it's call View) to
be diaplayed. We are designing the screen in xml fomrat as we seen
in Hello word case we have main.xml which is view for hello word
activity.
1. Android Framework:
Activity
●

In Activity code we setting up the view we have to write following code.
setContentView(R.layout.main);

●

Please note that we have to just mention R.layout.main not R.layout.
main.xml.
As discussed earlier(First PPT) please note that what ever views we are
creating for screen, we are putting it in res/layout folder.

●

●

There can be more than one activity in the app, and all activity must be
declared in the manifest file as follow.
<activity
android:name =".HelloWorldActivity"
android:label ="@string/app_name" >
<intent-filter >
<action android:name ="android.intent.action.MAIN" />
<category android:name ="android.intent.category.LAUNCHER"
/>
</intent-filter >
</activity>
1. Android Framework:
Activity
●

To declare activity in manifest file only <acivity> and </activity> tag is
enough but please note that in above there is also a <intent-filter> tag and
inside intent-filter there is action and category tag. This is for declaring the
activity which runs first when app is started. So from the category we can
figure out that this is the LAUNCHER activity.

●

We can set only one activity as a launcher activity.

●

To read More About Activity Please read:http://developer.android.
com/guide/components/activities.html
1. Android Framework:
Activity
1. Android Framework:
Service
2. Service:
●

Service is an application components that will run in background and do
not have user-interface.

●

Service is executing in background and provide result to activity so activity
updates the user-interface.

●

To user service in application we must have to register service in the
manifest file like activity.

●

To start service from activity Context.startService() is used.
1. Android Framework:
Broadcast Receiver
3. Broadcast Receiver:
●

Android broadcast event when ever some specified actions like call state is
changed (Incoming,outgoing),New Message,Battery is low etc.

●

So broadcast receiver is the application component which receives these
broadcast.

●

To use broadcast receiver we have to declare it in android.manifest or we
can register/unregister it from activity code.

<uses-permission
<receiver

android:name ="android.permission.READ_PHONE_STATE" />

android:name =".BootReceiver">
<intent-filter >
<action android:name ="android.intent.action.
BOOT_COMPLETED" />
</intent-filter >
</receiver>
1. Android Framework:
Service
●

So when ever phone state is changed from IDLE to RINGING our
broadcast receiver is called and we can handle the event.

●

Normally broadcast receiver have less time for execution so we should not
have to do processing much in broadcast receiver instead we should have
to start serivce and have more processing in service code.
1. Android Framework:
Content Providers
4. Content Providers:
●

Content Providers are used for data operations like storing and retrieving
the data.

●

Content providers manage access to a structured set of data. They
encapsulate the data, and provide mechanisms for defining data security .

●

Content providers are the standard interface that connects data in one
process with code running in another process. In short content provider
are more or less same like class any driver which we are normally using
database connection.

●

To read more about content provider please check link:http://developer.
android.com/guide/topics/providers/content-provider-basics.html
2. Android Layouts
●
●

●
●

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
Common Layout used in app design
1. Linear Layout
2. Relative Layout
3. List View
4. Grid View
2. Android Layouts
1.

Linear Layout : To create linear layout we need to add below code in
layout xml file.Using linear layout we can put other controls either vertically
or horizontally which we can define by android:orientation attribute.
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical" ></LinearLayout >
2. Android Layouts
2.Relative Layout : is a view group that
displays child views in relative positions. The
position of each view can be specified as
relative to sibling elements.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.
com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder" />

<Spinner
android:id="@+id/dates"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/times" />
<Spinner
android:id="@id/times"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentRight="true" />
<Button
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/times"
android:layout_alignParentRight="true"
android:text="@string/done" />
2. Android Layouts
2. Android Layout
3.Listview : ListView is a view group that displays a list of scrollable items. The
list items are automatically inserted to the list using an Adapter that pulls
content from a source such as an array or database query.
●

Lets take an example of network list displayed where we have to display
custom type of item.
2. Android Layout
Mian Activty Layout screen
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Network" >
<ListView
android:id="@+id/lvNetworkList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
</ListView>
</RelativeLayout>
2. Android Layout
List View Item Detail Desig
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.
com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/txtNetworkName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="22dp"
android:text="@string/network_name"
android:textAppearance="?android:attr/textAppearanceLarge"

<TextView
android:id="@+id/txtPortType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/txtNetworkType"
android:layout_alignBottom="@+id/txtNetworkType"
android:layout_alignParentRight="true"
android:layout_marginRight="22dp"
android:text="@string/port_type"
android:textColor="#AAA"
android:textAppearance="?android:
attr/textAppearanceMedium" />
<TextView
android:id="@+id/txtNetworkDscr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtNetworkName"
android:layout_alignRight="@+id/txtPortType"
android:layout_below="@+id/txtNetworkName"
android:text="@string/port_type"
android:textColor="#AAA"
android:textAppearance="?android:attr/textAppearanceSmall"

/>
<TextView
android:id="@+id/txtNetworkType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtNetworkName"
android:layout_below="@+id/txtNetworkName"
android:layout_marginTop="21dp"
android:text="@string/network_type"
android:textColor="#AAA"
android:textAppearance="?android:
attr/textAppearanceMedium" />

/>
</RelativeLayout>
2. Android Layout
Atcivity Code for Initialize listview
LayoutInflater inflater = (LayoutInflater)
context
private ListView lvNetworkListCode = (ListView) findViewById(R.id.
lvNetworkList);
public ArrayList<NetworkModel> Networks = new
ArrayList<NetworkModel>();
lvNetworkListCode.setAdapter(adapter);
ItemAdapter adapter = new ItemAdapter(this,R.layout.network_item,
Networks);
●

Here NetworkModel is the model class have attributes of
single item.
●
ItemAdapter class is the important it has getView method
which will iterate on models arraylist and print one byone item.
private final Context context;
private ArrayList<NetworkModel> Ids;
private final int rowResourceId;
public ItemAdapter(Context context, int resource,
ArrayList<NetworkModel> objects) {
super(context, resource, objects);
this.context = context;
this.Ids = objects;
this.rowResourceId = resource;
}

.getSystemService(Context.
LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate
(rowResourceId, parent, false);
txtNwNameCode = (TextView) rowView.
findViewById(R.id.txtNetworkName);
txtNwDscrCode = (TextView) rowView.
findViewById(R.id.txtNetworkDscr);
txtNwTypeCode = (TextView) rowView.findViewById(R.id.
txtNetworkType);
txtPortTypeCode = (TextView) rowView.
findViewById(R.id.txtPortType);
if (Ids.size() > 0) {
// setting values from model
txtNwNameCode.setText(Ids.get
(position).getNetworkName());
txtNwDscrCode.setText(Ids.get
(position).getNetworkDescr());
txtNwTypeCode.setText("N/W Type:
"+Ids.get(position).getNetworkType());
txtPortTypeCode.setText("Port Type:
"+Ids.get(position).getPortType());

@Override
public View getView(int position, View convertView,
ViewGroup parent) {

}
return rowView;
3. Basic UI Widgets
●
●

In section we will see how to add basic UI controls like text-box,label,
button and checkbox.
Lets consider below UI if we wanted to design.
3. Basic UI Widgets
Layout Design
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.
com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/enterNameLable" />
<EditText
android:id="@+id/nameTxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/enterNameHint" />
<CheckBox
android:id="@+id/appendHelloCheck"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/appendHello" />
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/maleradio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/maleLbl"/>

<RadioButton
android:id="@+id/femaleradio"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/femaleLbl" />
</RadioGroup>
<Button
android:id="@+id/showDataBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/okBtnTxt" />
<TextView
android:id="@+id/resultText"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ImageView
android:src="@drawable/maktabah"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="@+string/Image" />
</LinearLayout>
3. Basic UI Widgets
Activity Code:

OnClickListener showDataClickListener =new OnClickListener() {

public class Tutorial1Activity extends Activity {

@Override
public void onClick(View v) {

private Button showDataBtn;
String userName = userNametxt.getText().
private EditText userNametxt;
private CheckBox appendCheck;
private RadioGroup maleFemaleRadioGroup;
private TextView resultantText;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen1);
initViewCOntrols();
}
public void initViewCOntrols()
{
userNametxt = (EditText) findViewById(R.id.nameTxt);
appendCheck = (CheckBox) findViewById(R.id.
appendHelloCheck);
maleFemaleRadioGroup = (RadioGroup) findViewById(R.id.
radioGroup);

toString();
if(userName.length()>0){
RadioButton maleFRadio =
(RadioButton) findViewById(maleFemaleRadioGroup.
getCheckedRadioButtonId());
if(appendCheck.isChecked()){
resultantText.setText("Hello
"+userName+" n You are"+maleFRadio.getText().toString());
}else
{
resultantText.setText
(userName+" n You are"+maleFRadio.getText().toString());
}
}else
{
userNametxt.setError("Please Enter
Name.");
}

showDataBtn = (Button) findViewById(R.id.showDataBtn);
resultantText = (TextView) findViewById(R.id.resultText);

}
};

showDataBtn.setOnClickListener(showDataClickListener);
}

}
Questions?
Android session 2

More Related Content

PDF
Android session 1
PDF
Android session 3
PPT
Day 4: Android: UI Widgets
PDF
Training android
PPTX
Android Workshop: Day 1 Part 3
PPTX
Android apps development
PPT
Multiple Activity and Navigation Primer
PDF
Marakana Android User Interface
Android session 1
Android session 3
Day 4: Android: UI Widgets
Training android
Android Workshop: Day 1 Part 3
Android apps development
Multiple Activity and Navigation Primer
Marakana Android User Interface

What's hot (20)

PPTX
Android Fundamental
PPT
Londroid Android Home Screen Widgets
PPTX
Android application-component
PPTX
Android UI
ODP
Ppt 2 android_basics
PDF
Android development module
PDF
Android UI Fundamentals part 1
PPT
Android development orientation for starters v4 seminar
PPTX
Day 15: Working in Background
PPTX
Introduction to android
PPT
android layouts
PPT
Day 3: Getting Active Through Activities
PPT
Android
PPT
View groups containers
PPTX
Android Development Made Easy - With Sample Project
PPT
Android tutorial
PPT
Android tutorial
PPT
Android tutorial
DOCX
What is Android?
PDF
Android Development: Build Android App from Scratch
Android Fundamental
Londroid Android Home Screen Widgets
Android application-component
Android UI
Ppt 2 android_basics
Android development module
Android UI Fundamentals part 1
Android development orientation for starters v4 seminar
Day 15: Working in Background
Introduction to android
android layouts
Day 3: Getting Active Through Activities
Android
View groups containers
Android Development Made Easy - With Sample Project
Android tutorial
Android tutorial
Android tutorial
What is Android?
Android Development: Build Android App from Scratch

Similar to Android session 2 (20)

PPTX
PPTX
Android apps development
PPT
introductiontoandroiddevelopment (2).ppt
DOCX
Android Tutorial For Beginners Part-1
PPTX
Android app fundamentals
PPTX
Project a day 2 android application fundamentals
PDF
Lecture3
PDF
Android Introduction Talk
PPTX
Android components
PPTX
Android - Activity, Services
PPT
Android Presentation for fundamental.ppt
PPT
"Android" mobilių programėlių kūrimo įvadas #2
PPTX
Android Development Basics
PDF
Android Development Tutorial
PDF
Workshop 04 android-development
PDF
Android development first steps
PPTX
mobile application development -unit-3-
PPTX
Android beginners David
PPTX
Introduction to Android Development
DOC
ANDROID LAB MANUAL.doc
Android apps development
introductiontoandroiddevelopment (2).ppt
Android Tutorial For Beginners Part-1
Android app fundamentals
Project a day 2 android application fundamentals
Lecture3
Android Introduction Talk
Android components
Android - Activity, Services
Android Presentation for fundamental.ppt
"Android" mobilių programėlių kūrimo įvadas #2
Android Development Basics
Android Development Tutorial
Workshop 04 android-development
Android development first steps
mobile application development -unit-3-
Android beginners David
Introduction to Android Development
ANDROID LAB MANUAL.doc

Recently uploaded (20)

PDF
Human Computer Interaction Miterm Lesson
PDF
Secure Java Applications against Quantum Threats
PDF
EGCB_Solar_Project_Presentation_and Finalcial Analysis.pdf
PDF
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...
PDF
Introduction to c language from lecture slides
PDF
Decision Optimization - From Theory to Practice
PDF
Altius execution marketplace concept.pdf
PDF
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
PPTX
Report in SIP_Distance_Learning_Technology_Impact.pptx
PPT
Overviiew on Intellectual property right
PDF
EIS-Webinar-Regulated-Industries-2025-08.pdf
PDF
TicketRoot: Event Tech Solutions Deck 2025
PDF
NewMind AI Journal Monthly Chronicles - August 2025
PDF
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
PPTX
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
PDF
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
PDF
Ebook - The Future of AI A Comprehensive Guide.pdf
PDF
Optimizing bioinformatics applications: a novel approach with human protein d...
PDF
Streamline Vulnerability Management From Minimal Images to SBOMs
PDF
Child-friendly e-learning for artificial intelligence education in Indonesia:...
Human Computer Interaction Miterm Lesson
Secure Java Applications against Quantum Threats
EGCB_Solar_Project_Presentation_and Finalcial Analysis.pdf
The Digital Engine Room: Unlocking APAC’s Economic and Digital Potential thro...
Introduction to c language from lecture slides
Decision Optimization - From Theory to Practice
Altius execution marketplace concept.pdf
GDG Cloud Southlake #45: Patrick Debois: The Impact of GenAI on Development a...
Report in SIP_Distance_Learning_Technology_Impact.pptx
Overviiew on Intellectual property right
EIS-Webinar-Regulated-Industries-2025-08.pdf
TicketRoot: Event Tech Solutions Deck 2025
NewMind AI Journal Monthly Chronicles - August 2025
ELLIE29.pdfWETWETAWTAWETAETAETERTRTERTER
From Curiosity to ROI — Cost-Benefit Analysis of Agentic Automation [3/6]
Slides World Game (s) Great Redesign Eco Economic Epochs.pdf
Ebook - The Future of AI A Comprehensive Guide.pdf
Optimizing bioinformatics applications: a novel approach with human protein d...
Streamline Vulnerability Management From Minimal Images to SBOMs
Child-friendly e-learning for artificial intelligence education in Indonesia:...

Android session 2

  • 1. Android Application Development Session-2 From Beginner to Advanced By : Ahesanali Suthar email:[email protected]
  • 2. Topics Covered 1. Android Framework (Activity,Service,Broadcastreceiver,Content Providers) 2. Android Layout 3. Basic UI Widgets (Button,TextBox,Choice Box)
  • 3. 1. Android Framework ● Android App framework have four basic components which are listed below 1. 2. Service. 3. Broadcast Receiver. 4. ● Activity. Content Providers We will see each component in small detail
  • 4. 1. Android Framework 1. Activity: ● An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map ● Each activity is given a window in which to draw its user interface. The window typically fills the screen. ● Activity handle events in short for a windows .NET programer Activity is a code that is generated when we place button in form and double click on it and Visual Studio IDE generate button1_click() method or function. ● Activity decides which Screen(in android terminology it's call View) to be diaplayed. We are designing the screen in xml fomrat as we seen in Hello word case we have main.xml which is view for hello word activity.
  • 5. 1. Android Framework: Activity ● In Activity code we setting up the view we have to write following code. setContentView(R.layout.main); ● Please note that we have to just mention R.layout.main not R.layout. main.xml. As discussed earlier(First PPT) please note that what ever views we are creating for screen, we are putting it in res/layout folder. ● ● There can be more than one activity in the app, and all activity must be declared in the manifest file as follow. <activity android:name =".HelloWorldActivity" android:label ="@string/app_name" > <intent-filter > <action android:name ="android.intent.action.MAIN" /> <category android:name ="android.intent.category.LAUNCHER" /> </intent-filter > </activity>
  • 6. 1. Android Framework: Activity ● To declare activity in manifest file only <acivity> and </activity> tag is enough but please note that in above there is also a <intent-filter> tag and inside intent-filter there is action and category tag. This is for declaring the activity which runs first when app is started. So from the category we can figure out that this is the LAUNCHER activity. ● We can set only one activity as a launcher activity. ● To read More About Activity Please read:http://developer.android. com/guide/components/activities.html
  • 8. 1. Android Framework: Service 2. Service: ● Service is an application components that will run in background and do not have user-interface. ● Service is executing in background and provide result to activity so activity updates the user-interface. ● To user service in application we must have to register service in the manifest file like activity. ● To start service from activity Context.startService() is used.
  • 9. 1. Android Framework: Broadcast Receiver 3. Broadcast Receiver: ● Android broadcast event when ever some specified actions like call state is changed (Incoming,outgoing),New Message,Battery is low etc. ● So broadcast receiver is the application component which receives these broadcast. ● To use broadcast receiver we have to declare it in android.manifest or we can register/unregister it from activity code. <uses-permission <receiver android:name ="android.permission.READ_PHONE_STATE" /> android:name =".BootReceiver"> <intent-filter > <action android:name ="android.intent.action. BOOT_COMPLETED" /> </intent-filter > </receiver>
  • 10. 1. Android Framework: Service ● So when ever phone state is changed from IDLE to RINGING our broadcast receiver is called and we can handle the event. ● Normally broadcast receiver have less time for execution so we should not have to do processing much in broadcast receiver instead we should have to start serivce and have more processing in service code.
  • 11. 1. Android Framework: Content Providers 4. Content Providers: ● Content Providers are used for data operations like storing and retrieving the data. ● Content providers manage access to a structured set of data. They encapsulate the data, and provide mechanisms for defining data security . ● Content providers are the standard interface that connects data in one process with code running in another process. In short content provider are more or less same like class any driver which we are normally using database connection. ● To read more about content provider please check link:http://developer. android.com/guide/topics/providers/content-provider-basics.html
  • 12. 2. Android Layouts ● ● ● ● 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 Common Layout used in app design 1. Linear Layout 2. Relative Layout 3. List View 4. Grid View
  • 13. 2. Android Layouts 1. Linear Layout : To create linear layout we need to add below code in layout xml file.Using linear layout we can put other controls either vertically or horizontally which we can define by android:orientation attribute. <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="16dp" android:paddingRight="16dp" android:orientation="vertical" ></LinearLayout >
  • 14. 2. Android Layouts 2.Relative Layout : is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android. com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:paddingLeft="16dp" android:paddingRight="16dp" > <EditText android:id="@+id/name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/reminder" /> <Spinner android:id="@+id/dates" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_below="@id/name" android:layout_alignParentLeft="true" android:layout_toLeftOf="@+id/times" /> <Spinner android:id="@id/times" android:layout_width="96dp" android:layout_height="wrap_content" android:layout_below="@id/name" android:layout_alignParentRight="true" /> <Button android:layout_width="96dp" android:layout_height="wrap_content" android:layout_below="@id/times" android:layout_alignParentRight="true" android:text="@string/done" />
  • 16. 2. Android Layout 3.Listview : ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query. ● Lets take an example of network list displayed where we have to display custom type of item.
  • 17. 2. Android Layout Mian Activty Layout screen <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Network" > <ListView android:id="@+id/lvNetworkList" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="vertical" > </ListView> </RelativeLayout>
  • 18. 2. Android Layout List View Item Detail Desig <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android. com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/txtNetworkName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="20dp" android:layout_marginTop="22dp" android:text="@string/network_name" android:textAppearance="?android:attr/textAppearanceLarge" <TextView android:id="@+id/txtPortType" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/txtNetworkType" android:layout_alignBottom="@+id/txtNetworkType" android:layout_alignParentRight="true" android:layout_marginRight="22dp" android:text="@string/port_type" android:textColor="#AAA" android:textAppearance="?android: attr/textAppearanceMedium" /> <TextView android:id="@+id/txtNetworkDscr" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/txtNetworkName" android:layout_alignRight="@+id/txtPortType" android:layout_below="@+id/txtNetworkName" android:text="@string/port_type" android:textColor="#AAA" android:textAppearance="?android:attr/textAppearanceSmall" /> <TextView android:id="@+id/txtNetworkType" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/txtNetworkName" android:layout_below="@+id/txtNetworkName" android:layout_marginTop="21dp" android:text="@string/network_type" android:textColor="#AAA" android:textAppearance="?android: attr/textAppearanceMedium" /> /> </RelativeLayout>
  • 19. 2. Android Layout Atcivity Code for Initialize listview LayoutInflater inflater = (LayoutInflater) context private ListView lvNetworkListCode = (ListView) findViewById(R.id. lvNetworkList); public ArrayList<NetworkModel> Networks = new ArrayList<NetworkModel>(); lvNetworkListCode.setAdapter(adapter); ItemAdapter adapter = new ItemAdapter(this,R.layout.network_item, Networks); ● Here NetworkModel is the model class have attributes of single item. ● ItemAdapter class is the important it has getView method which will iterate on models arraylist and print one byone item. private final Context context; private ArrayList<NetworkModel> Ids; private final int rowResourceId; public ItemAdapter(Context context, int resource, ArrayList<NetworkModel> objects) { super(context, resource, objects); this.context = context; this.Ids = objects; this.rowResourceId = resource; } .getSystemService(Context. LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate (rowResourceId, parent, false); txtNwNameCode = (TextView) rowView. findViewById(R.id.txtNetworkName); txtNwDscrCode = (TextView) rowView. findViewById(R.id.txtNetworkDscr); txtNwTypeCode = (TextView) rowView.findViewById(R.id. txtNetworkType); txtPortTypeCode = (TextView) rowView. findViewById(R.id.txtPortType); if (Ids.size() > 0) { // setting values from model txtNwNameCode.setText(Ids.get (position).getNetworkName()); txtNwDscrCode.setText(Ids.get (position).getNetworkDescr()); txtNwTypeCode.setText("N/W Type: "+Ids.get(position).getNetworkType()); txtPortTypeCode.setText("Port Type: "+Ids.get(position).getPortType()); @Override public View getView(int position, View convertView, ViewGroup parent) { } return rowView;
  • 20. 3. Basic UI Widgets ● ● In section we will see how to add basic UI controls like text-box,label, button and checkbox. Lets consider below UI if we wanted to design.
  • 21. 3. Basic UI Widgets Layout Design <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android. com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/enterNameLable" /> <EditText android:id="@+id/nameTxt" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/enterNameHint" /> <CheckBox android:id="@+id/appendHelloCheck" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/appendHello" /> <RadioGroup android:id="@+id/radioGroup" android:layout_width="fill_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/maleradio" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/maleLbl"/> <RadioButton android:id="@+id/femaleradio" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/femaleLbl" /> </RadioGroup> <Button android:id="@+id/showDataBtn" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/okBtnTxt" /> <TextView android:id="@+id/resultText" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <ImageView android:src="@drawable/maktabah" android:layout_width="fill_parent" android:layout_height="wrap_content" android:contentDescription="@+string/Image" /> </LinearLayout>
  • 22. 3. Basic UI Widgets Activity Code: OnClickListener showDataClickListener =new OnClickListener() { public class Tutorial1Activity extends Activity { @Override public void onClick(View v) { private Button showDataBtn; String userName = userNametxt.getText(). private EditText userNametxt; private CheckBox appendCheck; private RadioGroup maleFemaleRadioGroup; private TextView resultantText; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen1); initViewCOntrols(); } public void initViewCOntrols() { userNametxt = (EditText) findViewById(R.id.nameTxt); appendCheck = (CheckBox) findViewById(R.id. appendHelloCheck); maleFemaleRadioGroup = (RadioGroup) findViewById(R.id. radioGroup); toString(); if(userName.length()>0){ RadioButton maleFRadio = (RadioButton) findViewById(maleFemaleRadioGroup. getCheckedRadioButtonId()); if(appendCheck.isChecked()){ resultantText.setText("Hello "+userName+" n You are"+maleFRadio.getText().toString()); }else { resultantText.setText (userName+" n You are"+maleFRadio.getText().toString()); } }else { userNametxt.setError("Please Enter Name."); } showDataBtn = (Button) findViewById(R.id.showDataBtn); resultantText = (TextView) findViewById(R.id.resultText); } }; showDataBtn.setOnClickListener(showDataClickListener); } }