• RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
Posted by Jack - - 3 comments


COMBINING LAYOUTS IN A LAYOUT

The main.xml file is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Layout 1" />
<include android:id="@+id/cell1" layout="@layout/layout1" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Layout 2" />
<include android:id="@+id/cell2" layout="@layout/layout2" />
</LinearLayout>

The layout1.xml file is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
                android:layout_height="wrap_content"
android:background="#ff0000" >
<TextView android:layout_width="fill_parent"
                                android:layout_height="40px"
android:text="TextView" />
                <EditText android:layout_width="250px"
android:layout_height="wrap_content"
                                android:hint="EditText" />
                <CheckBox android:layout_width="fill_parent"
                                android:layout_height="40px"
android:text="Checkbox" />
</LinearLayout>

The layout2.xml file is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
                android:layout_height="wrap_content"
android:background="#00ff00" >
<TextView android:layout_width="fill_parent"
                                android:layout_height="40px"
android:text="TextView" />
                <EditText android:layout_width="250px"
android:layout_height="wrap_content"
                                android:hint="EditText" />
                <CheckBox android:layout_width="fill_parent"
                                android:layout_height="40px"
android:text="Checkbox" />
</LinearLayout>

The OUTPUT will be

https://lh6.googleusercontent.com/_xnrF0YSUul8/TYCnsBF17YI/AAAAAAAAAGY/09xXS0qfFyg/combining_layouts.png

Posted by Jack - - 0 comments

INTRODUCTION TO ANDROID

What is Android?

Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.

Features

·         Application framework enabling reuse and replacement of components.
·         Dalvik virtual machine optimized for mobile devices.
·         Integrated browser based on the open source WebKit engine.
·         Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional).
·         SQLite for structured data storage.
·         Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF).
·         GSM Telephony (hardware dependent).
·         Bluetooth, EDGE, 3G, and WiFi (hardware dependent).
·         Camera, GPS, compass, and accelerometer (hardware dependent).
·         Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE.

Android Architecture

The following diagram shows the major components of the Android operating system. Each section is described in more detail below.

https://lh3.googleusercontent.com/_xnrF0YSUul8/TYCaNhDkThI/AAAAAAAAAGQ/WrncJSJ9WeE/system-architecture.jpg
Applications

Android will ship with a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, and others. All applications are written using the Java programming language.

Application Framework

By providing an open development platform, Android offers developers the ability to build extremely rich and innovative applications. Developers are free to take advantage of the device hardware, access location information, run background services, set alarms, add notifications to the status bar, and much, much more.
Developers have full access to the same framework APIs used by the core applications. The application architecture is designed to simplify the reuse of components; any application can publish its capabilities and any other application may then make use of those capabilities (subject to security constraints enforced by the framework). This same mechanism allows components to be replaced by the user.
Underlying all applications is a set of services and systems, including:
·         A rich and extensible set of Views that can be used to build an application, including lists, grids, text boxes, buttons, and even an embeddable web browser.
·         Content Providers that enable applications to access data from other applications (such as Contacts), or to share their own data.
·         A Resource Manager, providing access to non-code resources such as localized strings, graphics, and layout files.
·         A Notification Manager that enables all applications to display custom alerts in the status bar.
·         An Activity Manager that manages the lifecycle of applications and provides a common navigation backstack.

Libraries

Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. Some of the core libraries are listed below:
·         System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices.
·         ]Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG.
·         Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications.
·         LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view.
·         SGL - the underlying 2D graphics engine.
·         3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer.
·         FreeType - bitmap and vector font rendering.
·         SQLite - a powerful and lightweight relational database engine available to all applications.

Android Runtime

Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.
Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool.
The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.

Linux Kernel

Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.

Posted by Jack - - 0 comments

ANDROID EMULATOR


The Android emulator is probably the most powerful tool at a developer’s disposal.
It is important for developers to learn to use the emulator and understand its limitations.
The Android emulator is integrated with Eclipse, using the ADT plug-in for the Eclipse IDE.

Emulator Limitations

The Android emulator is a convenient tool, but it has a number of limitations:

·         The emulator is not a device. It simulates general handset behavior, not specific hardware implementations.
·         Sensor data, such as satellite location information, battery and power settings, and network connectivity, are all simulated using your computer.
·         Peripherals such as camera hardware are not fully functional.
·         Phone calls cannot be placed or received but are simulated. SMS messages are also simulated and do not use a real network.
·         No USB or Bluetooth support is available.

Using Android emulator is not a substitute for testing on a true target handset or device.

https://lh3.googleusercontent.com/_xnrF0YSUul8/TYBrnvEAsFI/AAAAAAAAAFs/o8N1qy8TwRA/emulator.png

Posted by Jack - - 4 comments


SIMPLE SPINNER

SOURCE CODE [main.xml] is

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">
<Spinner android:id="@+id/spin"
android:layout_width="150px"
android:layout_height="wrap_content"
android:layout_gravity="center">
</Spinner>
</LinearLayout>

SOURCE CODE [SpinnerExample.java] is

package com.SpinnerExample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

public class SpinnerExample extends Activity
{
Spinner sp;
                ArrayAdapter<String> adapter;
                String numbers[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN",
                                                "EIGHT", "NINE", "TEN" };

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
                                setContentView(R.layout.main);

                                sp = (Spinner) findViewById(R.id.spin);
                               
                                adapter = new ArrayAdapter<String>(this,
                                                                android.R.layout.simple_spinner_item, numbers);
                                sp.setAdapter(adapter);
                }
}

The OUTPUT will be

https://lh3.googleusercontent.com/_xnrF0YSUul8/TX9dHNJfmpI/AAAAAAAAAFY/t2kql7Ybrx0/simple_spinner1.png https://lh6.googleusercontent.com/_xnrF0YSUul8/TX9dHXMNvZI/AAAAAAAAAFc/fL4WJN4N1D4/simple_spinner2.png

Posted by Jack - - 39 comments

SEARCH IN LISTVIEW


SOURCE CODE [main.xml] is


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical">
<EditText android:id="@+id/EditText01"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="Search">
</EditText>

<ListView android:id="@+id/ListView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>



SOURCE CODE [ListViewSearchExample.java] is


package com.ListViewSearchExample;

import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class ListViewSearchExample extends Activity
{
private ListView lv;
private EditText et;
private String listview_array[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE",
"SIX", "SEVEN", "EIGHT", "NINE", "TEN" };
private ArrayList<String> array_sort= new ArrayList<String>();
int textlength=0;

public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

lv = (ListView) findViewById(R.id.ListView01);
et = (EditText) findViewById(R.id.EditText01);
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listview_array));

et.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
                                                                // Abstract Method of TextWatcher Interface.
}
public void beforeTextChanged(CharSequence s,
int start, int count, int after)
{
// Abstract Method of TextWatcher Interface.
}
public void onTextChanged(CharSequence s,
int start, int before, int count)
{
textlength = et.getText().length();
array_sort.clear();
for (int i = 0; i < listview_array.length; i++)
{
if (textlength <= listview_array[i].length())
{
if(et.getText().toString().equalsIgnoreCase(
(String)
listview_array[i].subSequence(0,
textlength)))
{
                                                                                                                array_sort.add(listview_array[i]);
                                                                                                }
                                                                                }
                                                                }
lv.setAdapter(new ArrayAdapter<String>
(ListViewSearchExample.this,
android.R.layout.simple_list_item_1, array_sort));
}
});
}
}


The OUTPUT will be


https://lh3.googleusercontent.com/_xnrF0YSUul8/TXnIae2ouyI/AAAAAAAAAFI/zzb3rTmUZMo/listview_search1.png https://lh3.googleusercontent.com/_xnrF0YSUul8/TXnIaULcKAI/AAAAAAAAAFE/-OprcK5ppSI/listview_search2.png

Posted by Jack - - 0 comments


SIMPLE LISTVIEW
 

SOURCE CODE [main.xml] is 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
                android:layout_width="fill_parent"
android:layout_height="fill_parent"
                xmlns:android="http://schemas.android.com/apk/res/android">
                <ListView android:id="@+id/listview"
android:layout_width="wrap_content"
                                android:layout_height="wrap_content" />
</LinearLayout>



SOURCE CODE [ListViewExample.java] is 

package com.ListViewExample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListViewExample extends Activity
{
                private ListView lv;
                private String listview_array[] = { "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX",
                                                "SEVEN", "EIGHT", "NINE", "TEN" };

                public void onCreate(Bundle icicle)

{
                                super.onCreate(icicle);
                                setContentView(R.layout.main);
                                lv = (ListView) findViewById(R.id.listview);
lv.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listview_array));
                }
}
 

The OUTPUT will be

https://lh4.googleusercontent.com/_xnrF0YSUul8/TXm5AyifxOI/AAAAAAAAAE8/T_khVQrgLr4/simple_listview.png