AT&T Developer
  • Products
  • Resources
  • Blog
  • Sign In

Technical Library

    Device Technologies
    • Biometrics
    • Device Detection
    • HTML5
    • Mobile Web Fundamentals
    • Mobile Web Standards
    • Multi Core Coding in Dalvik
    • Multi Thread Coding in Android
    • Near Field Communication
    • NFC Forum
    • NFC Use Cases
    • NFC Case Studies
    • NFC Tags
    • GlobalPlatform and NFC
    • User Identification
    • Native Code
    Security and Privacy
    • Application Privacy Guidelines
    • Downloading DRM Content in Android
    • IPv6
    • Likelihood of a Successful Attack
    • Messaging Privacy
    • Mobile Web Security
    • Network Security
    • Security Policy
    • Security at AT&T
    • Types of Security Threats
    • Wireless Application Security
    • Security Policy Enforcement
    UI Elements
    • Slider Controls for Android
    • Check Box for Android
    • Dropdown for Android
    • Image Button for Android
    • Toggle Button for Android
    • Radio Button for Android
    • Segmented Text Toggle Button for Android
    • Static Text Toggle Button for Android
    • Switch for Android
    • Text Fields for Android
    • Getting Started with AT&T UI
    • HTML5 UI Elements
    • HTML5 Checkboxes
    • HTML5 Dropdown
    • HTML5 Image Button
    • HTML5 Image Toggle Button
    • HTML5 Radio Button
    • HTML5 Segmented Toggle Button
    • HTML5 Slider
    • HTML5 Static Text Toggle Button
    • HTML5 Switch Control
    • HTML5 Text Fields
    Network Technologies
    • IP Addresses
    • Long Term Evolution (LTE)
    • Network Timers
    • Wi-Fi
  • Other AT&T Websites
  • Best Practices
    • Hackathon Best Practices
    • Mobile Best Practices
    • Seven Common Errors Around Creating Mobile User Experiences
toggle menu

Dropdown for Android™

 

A Dropdown List UI element enables users to choose between multiple items in a list. These UI elements have three states: default, pressed, and disabled. The current item is checked and the user is allowed to scroll through the list.

Download UI elements for Android.

 

Creation

 

You need to create a new com.att.widgets.lib.dropdown.DropDown object and add it to your view or layout.

 

Full layout code


<?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="This is a sample of 3 Dropdowns"
android:paddingBottom="10dp"
android:textStyle="bold"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp">
<TextView android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:text="Andriod Os:"/>
<com.att.widgets.lib.dropdown.DropDown
android:id="@+id/dropdown"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout android:id="@+id/dropdown_2_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp">
<TextView android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:text="Phones:"/>
</LinearLayout>
<TextView android:id="@+id/dropdown_text_1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/dropdown_text_2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dip">
<TextView android:layout_width="100dip"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:text="Disabled Dropdown:"/>
<com.att.widgets.lib.dropdown.DropDown
android:id="@+id/dropdown_disabled"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>

 

Activity

 

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.att.widgets.lib.dropdown.DropDown;
public class DropDownActivity extends Activity implements OnClickListener {
private String[]array_1 = {"Gingerbread", "Froyo", "Cupcake", "Donut", "Eclair"};
private String[]array_2 = {"Milestone", "Galaxy", "Nexus One", "MotoBlur"};
private DropDown dropDown_1, dropDown_2;
private TextView textView_1, textView_2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ViewGroup v = (ViewGroup)findViewById(R.id.dropdown_2_view);
textView_1 = (TextView)findViewById(R.id.dropdown_text_1);
textView_2 = (TextView)findViewById(R.id.dropdown_text_2);
dropDown_1 = ((DropDown)findViewById(R.id.dropdown));
dropDown_1.setFocusable(true);
dropDown_2 = new DropDown(this);
RelativeLayout.LayoutParams ll = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
dropDown_2.setLayoutParams(ll);
v.addView(dropDown_2);
dropDown_1.setData(array_1);
dropDown_2.setData(array_2);
dropDown_1.setFieldsNumber(4);
dropDown_2.setFieldsNumber(3);
((DropDown)findViewById(R.id.dropdown_disabled)).setEnabled(false);
((DropDown)findViewById(R.id.dropdown_disabled)).setDisplayText("Disabled Dropdown");
//listeners
dropDown_1.setOnClickListener(this);
dropDown_2.setOnClickListener(this);
}
public void onClick(View v) {
if(v == dropDown_1){
textView_1.setText("Selected Android Os: " + dropDown_1.getSelectedText());
}else if(v == dropDown_2){
textView_2.setText("Selected Phone: " +dropDown_2.getSelectedText());
}
}
}

 

Explanation

 

The first Dropdown is defined in Xml with the id "dropdown", and focused by code

First Drop Down Layout


<com.att.widgets.lib.dropdown.DropDown
android:id="@+id/dropdown" android:layout_width="fill_parent"
android:layout_height="wrap_content" />

 

First Drop Down Activity Code


dropDown_1 = ((DropDown)findViewById(R.id.dropdown));
dropDown_1.setFocusable(true);
dropDown_1.setData(array_1);
dropDown_1.setOnClickListener(this);
// Number of fields visible on the drop down list
dropDown_1.setFieldsNumber(4);

 

Second Drop Down Layout

And the second DropDown is generated from the following code. Only LinearLayout is defined in the xml

 <LinearLayout android:id="@+id/dropdown_2_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>


Second Drop Down Activity Code


ViewGroup v = (ViewGroup)findViewById(R.id.dropdown_2_view);
dropDown_2 = new DropDown(this);
RelativeLayout.LayoutParams ll = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
dropDown_2.setLayoutParams(ll);
v.addView(dropDown_2);
dropDown_2.setFocusable(true);
dropDown_2.setData(array_2);
dropDown_2.setOnClickListener(this);
//number of fields visible on the drop down list
dropDown_2.setFieldsNumber(3);


You can choose how you want to do it.

 

Click listeners

You should add a click listener to handle the selection event

dropDown.setOnClickListener(this);


and implement the OnClickListener in the current class. For example:

public class DropDownActivity extends Activity implements OnClickListener
...
public void onClick(View v) {
...
}

Android is a trademark of Google Inc.

Back To Top
  • APIS & TOOLS
    • AT&T Video Optimizer
  • APIS & TOOLS
    • Futurist Reports
    • Technical Library
  • SUPPORT
    • Contact Us
    • FAQs
    • Twitter
  • AT&T Developer Program on Github
  • AT&T Developer Program on Facebook
  • AT&T Developer Program on Twitter
AT&T Logo

Terms of Use   Privacy Policy   Your Privacy Choices California Consumer Privacy Act (CCPA) Opt-Out Icon
©2025 AT&T Intellectual Property. All rights reserved

AT&T, the AT&T logo and all other AT&T marks contained herein are trademark of AT&T Intellectual Property and/or AT&T affiliated companies.

14100000
Session Expiring

Your session is about to expire in !

Stay Signed In
Session Expired

Sorry! Your session has expired.

Skip to content