Expandable lists

Double up: using expandable lists

Android ExpandableListView expandableList icon

Expandable lists let you create lists within lists.

They’re ideal for list items that have sub-categories. The user selects an item from a scrollable list and another list pops open. They can then make another selection from this list.

Adding menus programmatically

Creating menus in code

Android add menu programmatically icon

It’s best to define your menus in XML in a menu resource file. However, sometimes you may want to create or modify a menu programmatically.

We’ll show you how to create and modify your menus in code.

We’re using the support library so that our code will work on devices running Android 2.1.x (API Level 7) and higher.

Context

Android context icon

The Context class gives you access to the global information about an application’s environment. It lets you:

  • Access the apps resources and classes
  • Communicate with other app components

All spaced out!

Android gravity, layout_gravity, padding and margins icon

Don’t be confused by:

  • The gravity and layout_gravity attributes
  • padding and margins

Check out these quick examples…

How to keep your clothes on and have fun with text!

Android TextView icon

You use the TextView class to display text to the user.

Although you can also edit the text displayed in text views, it’s best to use the TextView subclass, EditText to do that.

The TextView class has a number of attributes that you can use to make your text really stand out. We’ll show you a few to whet your appetite.

Read on to see how to:

  • Create and position a TextView in a RelativeLayout in code
  • Add shadows to your text
  • Rotate your text
  • How to use different font families to impress with your text

Throw your weight around

Android layout_weight attribute weight icon

Linear layouts support a layout_weight attribute.

We can use the weight attribute to allocate a portion of the layout’s space to a view, depending on its weight.

All views have a default weight of 0.

You can set a weight attribute using a float value for any view that you use in a LinearLayout. Android will then divide the available space up amongst the views proportionately, depending on their weight values.

Softly, softly. Using Android’s soft keyboard: A tutorial

Android soft keyboard tutorial icon

In the introduction, we covered the basics of using soft keyboards.  If you haven’t read it yet, you’ll find it here: Android’s soft keyboard. An introduction.

In this tutorial, we’ll show you how to use the soft keyboard in your apps.

Softly, softly. Using Android’s soft keyboard: An introduction

Android soft keyboard introduction icon

Need to capture text input in your app?

Android supports an on-screen soft keyboard as well as attached hardware keyboards.

The soft keyboard appears when a text field is in focus and disappears when it’s out of focus. The keyboard positions itself at the bottom of the screen over the app window. It has its own editing area.

In this introduction, we’ll cover the basics of using soft keyboards. Later, in a follow up tutorial, we’ll show you how to use the soft keyboard in your apps.

Localizing your resources

Keeping it local

Android localisation icon

Android apps can be installed on devices around the world. If you want to distribute your app to this large market, then you should provide alternative resources such as text, sound and images.

Android makes it easy to include alternative strings, sound files, layouts and images so that your app will work in any country and in any language.

Our tutorial app will show you how to include alternative text and image resources.

Android's SeekBar: a tutorial

Using a SeekBar to change the size of text in a TextView

Android SeekBar icon

Seek Bars are like Progress Bars, with a slight difference. The user determines the progress by moving a slider.

We’ll show you how to use a SeekBar to change the size of text in a TextView.