IT tutorials
 
Mobile
 

Android 3 : Employing Basic Widgets - Fleeting Images, Fields of Green...or Other Colors

5/9/2013 3:21:14 AM
- How To Install Windows Server 2012 On VirtualBox
- How To Bypass Torrent Connection Blocking By Your ISP
- How To Install Actual Facebook App On Kindle Fire

1. Fleeting Images

Android has two widgets to help you embed images in your activities: ImageView and ImageButton. As the names suggest, they are image-based analogues to TextView and Button, respectively.

Each widget takes an android:src attribute (in an XML layout) to specify which picture to use. These attributes usually reference a drawable resource.

ImageButton, a subclass of ImageView, mixes in the standard Button behaviors, for responding to clicks and whatnot. For example, take a peek at the main.xml layout from the Basic/ImageView sample project:

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/icon"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:adjustViewBounds="true"
    android:src="@drawable/molecule"
    />

The result, just using the code-generated activity, is simply the image, as shown in Figure 1.

Figure 1. The ImageViewDemo sample application

2. Fields of Green...or Other Colors

Along with buttons and labels, fields are the third anchor of most GUI toolkits. In Android, they are implemented via the EditText widget, which is a subclass of the TextView used for labels.

Along with the standard TextView properties (e.g., android:textStyle), EditText has many other properties that will be useful to you in constructing fields, including the following:

  • android:autoText: Controls if the field should provide automatic spelling assistance

  • android:capitalize: Controls if the field should automatically capitalize the first letter of entered text (e.g., in name and city fields)

  • android:digits: Configures the field to accept only certain digits

  • android:singleLine: Controls if the field is for single-line input or multiple-line input (e.g., does pressing Enter move you to the next widget or add a newline?)

Most of the preceding properties are also available from the new android:inputType attribute, added in Android 1.5 as part of adding "soft keyboards" to Android .

For example, from the Basic/Field project, here is an XML layout file showing an EditText widget:

<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/field"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:singleLine="false"
  />

Note that android:singleLine is set to "false", so users will be able to enter several lines of text.

For this project, the FieldDemo.java file populates the input field with some prose:

package com.commonsware.android.field;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

public class FieldDemo extends Activity {
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    EditText fld=(EditText)findViewById(R.id.field);
    fld.setText("Licensed under the Apache License, Version 2.0 " +
            "(the \"License\"); you may not use this file " +
            "except in compliance with the License. You may " +
            "obtain a copy of the License at " +
            "http://www.apache.org/licenses/LICENSE-2.0");
  }
}

The result, once built and installed into the emulator, is shown in Figure 2.

Another flavor of field is one that offers autocompletion, to help users supply a value without typing in the whole text. That is provided in Android as the AutoCompleteTextView widget.

Figure 2. The FieldDemo sample application
 
Others
 
- Android 3 : Employing Basic Widgets - Assigning Labels
- Symbian OS : Security - Buckle
- Symbian OS : Security - Secure Agent
- iOS SDK : Application Settings - The Settings Bundle (part 4) - PSSliderSpecifier, PSChildPaneSpecifier
- iOS SDK : Application Settings - The Settings Bundle (part 3) - PSMultiValueSpecifier
- iOS SDK : Application Settings - The Settings Bundle (part 2) - Settings Field Types
- iOS SDK : Application Settings - The Settings Bundle (part 1)
- Ipad : Your Calendar - Calendar Options - Changing the Default Calendar
- Ipad : Your Calendar - Editing Appointments, Meeting Invitations
- BlackBerry Bold 9700 and 9650 Series : Email Set Up - BlackBerry Enterprise Server Express
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
programming4us programming4us
 
Popular tags
 
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8 BlackBerry Android Ipad Iphone iOS