blob: e9d22e641f824f1c15e4067403693d3f2b316cef [file] [log] [blame]
Roman Nurikb99ae732012-03-06 12:26:15 -08001page.title=Selection
2@jd:body
3
Peter Ng02123632012-08-06 11:44:48 -07004<p>Android 3.0 changed the <em>long press</em> gesture&mdash;that is, a touch that's held in the same position for a moment&mdash;to be the global gesture to select data.. This affects the way you should
Roman Nurikb99ae732012-03-06 12:26:15 -08005handle multi-select and contextual actions in your apps.</p>
6
7<div class="vspace size-1">&nbsp;</div>
8
9<div class="layout-content-row">
10 <div class="layout-content-col span-6">
11
12<h4>What has changed?</h4>
13<p>In previous versions of Android, the long press gesture was universally used to display contextual
14actions for a given data item in a contextual menu.</p>
15<p>This pattern changed with Android 3.0. The long press gesture is now used to select data, combining
16contextual actions and selection management functions for selected data into a new element called
17the contextual action bar (CAB).</p>
18
19 </div>
20 <div class="layout-content-col span-7">
21
22 <img src="{@docRoot}design/media/selection_context_menu.png">
23 <div class="figure-caption">
24 Traditional use of the long press gesture to show contextual menus.
25 </div>
26
27 </div>
28</div>
29
30<h4>Using the contextual action bar (CAB)</h4>
31<p>The selection CAB is a temporary action bar that overlays your app's current action bar while data
32is selected. It appears after the user long presses on a selectable data item.</p>
33
34<img src="{@docRoot}design/media/selection_cab_big.png">
35
36<div class="vspace size-1">&nbsp;</div>
37
38<div class="layout-content-row">
39 <div class="layout-content-col span-6">
40
41<p>From here the user can:</p>
42<ul>
43<li>Select additional data items by touching them.</li>
44<li>Trigger an action from the CAB that applies to all highlighted data items. The CAB then
45 automatically dismisses itself.</li>
46<li>Dismiss the CAB via the navigation bar's Back button or the CAB's checkmark button. This removes
47 the CAB along with all selection highlights.</li>
48</ul>
49
50 </div>
51 <div class="layout-content-col span-7">
52
53 <img src="{@docRoot}design/media/selection_cab_example.png">
54
55 </div>
56</div>
57
58<div class="layout-content-row">
59 <div class="layout-content-col span-6">
60
61<h4>Selecting CAB actions</h4>
62<p>You can decide which actions and elements appear in the CAB. Use the guidelines in the <a href="actionbar.html">Action Bar
63pattern</a> to decide which items to surface at the top level and which to move to the
64action overflow.</p>
65<h4>Dynamically adjust CAB actions</h4>
66<p>In most cases you need to adjust the actions in the CAB dynamically as the user adds more items to
67the selection. Actions that apply to a single selected data item don't necessarily apply to multiple
68selected data items of the same kind.</p>
69
70 </div>
71 <div class="layout-content-col span-7">
72
73 <img src="{@docRoot}design/media/selection_adjusting_actions.png">
74 <div class="figure-caption">
75 Adjusting actions in the CAB as additional items are selected.
76 </div>
77
78 </div>
79</div>
80
Scott Main2ed01ad2012-10-04 11:14:01 -070081<div class="note develop">
82<p><strong>Developer Guide</strong></p>
83 <p>For information about how to create a contextual action bar, read
84 <a href="{@docRoot}guide/topics/ui/menus.html#CAB">Using the contextual action mode</a>.</p>
85</div>
86
87
Roman Nurikb99ae732012-03-06 12:26:15 -080088<h2 id="checklist">Checklist</h2>
89
90<ul>
91<li>
92<p>Whenever your app supports the selection of multiple data items, make use of the contextual action
93 bar (CAB).</p>
94</li>
95<li>
96<p>Reserve the long press gesture for selection exclusively. Don't use it to display traditional
97 contextual menus.</p>
98</li>
99<li>
100<p>If you don't support multi-selection within a list, long press should do nothing.</p>
101</li>
102<li>
103<p>Plan the actions you want to display inside of a CAB in the same way you would plan the actions
104 inside your app's action bar.</p>
105</li>
106</ul>