Android2EE

  • Adapté
  • Large
  • Etroit
  • Increase font size
  • Default font size
  • Decrease font size
Prochaines formations Android inter-entreprises par Android2EE

Inscrivez-vous.

Inscrivez-vous dès maintenant.
N'attendez pas que les formations soient remplies (8 places maximum).

par mail : contact@android2ee.com ou

par téléphone 06 50 48 24 93. 
Du 24 au 28 Juin
Du 23 au 27 Sept.
Du 18 au 22 Nov. 
Paris  Formation Init.: Des fondamentaux à l'autonomie et la performance (3j)
Formation complète: Fondamentaux, Architecture et Android 4 (5j) 
Du 07 au 11 Oct.  Lyon Formation Init.: Des fondamentaux à l'autonomie et la performance (3j)
Formation complète : Fondamentaux, Architecture et Android 4 (5j) 
Du 16 au 20 Sept.
Du 25 au 29 Nov.
 

Toulouse
Formation Init.: Des fondamentaux à l'autonomie et la performance (3j)
Formation complète : Fondamentaux, Architecture et Android 4 (5j) 
La conférence "Android a Quick Course" est disponible, n'hésitez pas à la visionner. ici

Participez aux formations Android2EE et gagnez peut-être le Nexus (plus d'informations)

Lancement dès Octobre 2013 de la fromation Android 4+ dédiée à HoneyComb, IceCreamSandwich et JellyBean. Stay Tuned

Beginning of the Chapite 3.4 Selection widgets

E-mail Print PDF
3.4    Selection widgets
These widgets are used for helping you with writing or for selecting elements.
These widgets rely on adaptors that offer you a common interface for the underlying data models of a data selection widget. They provide the data list and convert it into different specific views that are then used by the selection widget for display operations.

3.4.1    The selectors
There are 6 different types of selection lists:
  • The basic list : ListView
  • The combo box : Spinner
  • GridView :  displays choices on a grid and are often used for selecting images 
  • AutoCompleteTextView : uses the User input to filter data and display a data subset. Data is displayed as with Spinner.
  • Galleries : they display data as a horizontal list and are often used for selecting images 

3.4.2    An example for ListView with an activity that extends ListView :
This example shows a list and a text field. When an item of the list is clicked upon, the text field retrieves the value of the selected item. 
There are 3 important things to take into account for this first example:
  • The use of android.R.layout.simple_list_item_1 in the definition of the ArrayAdapter will define how the items of the list will be presented.
  • The use of the tag @android :id/list as the identifier for the ListView means it will be automatically interpreted as being the principal list.
  • My activity extends ListActivity.

 
 
 
 

/** 

* @author mathias seguy 

* @goals This class aims to show a simple List Activity 

*/ 

public class ListViewTuto extends ListActivity { 

/*** A text view  */ 

TextView textView;

/*** The dummy data list */

String[] items = {"item1","item2","item3","item4","item5","item6" };

/** *The arrayAdapter that manage the data displayed          */

ArrayAdapter<String> arrayAdapter;

@Override

public void onCreate(Bundle icicle) {

super.onCreate(icicle);

setContentView(R.layout.main);

// Define the Adapter (Context, ListView Ressource, The items to display)

arrayAdapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);

//or using string values stored in the resources:

String[] itemsFromRes=getResources().getStringArray(R.array.itemsList);

arrayAdapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,

itemsFromRes);

//Set the ArrayAdapter to the ListActivity

setListAdapter(arrayAdapter);

//The text view that displays the current selected item

textView = (TextView) findViewById(R.id.text);

}

/* (non-Javadoc)@see android.app.ListActivity#onListItemClick(android.widget.ListView, android.view.View, int, long)

*/

public void onListItemClick(ListView parent, View v, int position, long id) {

textView.setText(items[position]);

}

}


 
  Mathias Séguy

Where the xml file that declares the graphic elements is:

 

 
 
 
 
 

<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:id="@+id/text"

android:layout_width="fill_parent"

android:layout_height="wrap_content"/>

<ListView

android:id="@android:id/list"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:drawSelectorOnTop="false"

/>

LinearLayout>

  Mathias Seguy

This goes in strings.xml :
 
 
 
 

 

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="hello">Hello World, ListViewTuto!</string>

<string name="app_name">ListViewTuto2</string>

<string-array>

<item>items1</item>

<item>items2</item>

<item>items3</item>

<item>items4</item>

<item>items5</item>

<item>items6</item>

</string-array>

</resources>
  Mathias Séguy
You are here Examples Complet Course Chapter 3.4 widgets selections