Android TutorialsNo Comments

default thumbnail
312 views.

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 and converts each item result into a view that’s placed into the list.

Above is the standard syntax for simple list view below will see each word detail in above syntax.

Array: 

An array is a collection of similar data types. Array is a container object that hold values of homogenous type. It is also known as static data structure because size of an array must be specified at the time of its declaration.

An array can be either primitive or reference type. It gets memory in heap area. Index of array starts from zero to size-1.

Array Declaration

Syntax :

datatype[ ] identifier;
or
datatype identifier[ ];
Both are valid syntax for array declaration. But the former is more readable.

Example :

int[ ] arr;
char[ ] arr;
short[ ] arr;
long[ ] arr;
int[ ][ ] arr; // two dimensional array.
Initialization of Array

new operator is used to initialize an array.

Example :

int[ ] arr = new int[10]; //10 is the size of array.
or
int[ ] arr = {10,20,30,40,50};
Accessing array element

As mention ealier array index starts from 0. To access nth element of an array. Syntax

arrayname[n-1];

ArrayAdapter:

In simple terms, an Adaptor is a collection handler that returns each item in the collection as a view. ArrayAdaptor is one of many adaptors available in Android

The ArrayAdapter class can handle a list or array of Java objects as input. Every Java object is mapped to one row. By default it maps the toString() method of the object to a view in the row layout.

An adapter is used for managing the items in the list (the data model or data source). In simple terms, an Adaptor is a collection handler that returns each item in the collection as a view. ArrayAdaptor is one of many adaptors available in Android

The ArrayAdapter class can handle a list or array of Java objects as input. Every Java object is mapped to one row. By default it maps the toString() method of the object to a view in the row layout.

An adapter is used for managing the items in the list (the data model or data source).

Context:

Context refers super class name reference in our class. In android context we can refer in 3 ways

  1. GetApplicationContext()
  2. Classname.this
  3. getActivity() this we can use only in Fragments.

Layout Resource:

Layout resource we can refer in two ways

  1. Predefined
  2. Custom

this layout contains only textview styles that we can observe in below example.

Array Resource:

Array Resource we can refer in three ways

  1. Array from Java
  2. Array from String.xml
  3. Array from Database (server)

below example we can observe different combinations.

activity_main.xml

String.xml

custom.xml

MainActivity.java

 

Be the first to post a comment.

Add a comment