Home | History | Annotate | Download | only in patterns
      1 page.title=Selection
      2 @jd:body
      3 
      4 <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
      5 handle 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
     14 actions 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
     16 contextual actions and selection management functions for selected data into a new element called
     17 the 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
     32 is 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
     63 pattern</a> to decide which items to surface at the top level and which to move to the
     64 action 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
     67 the selection. Actions that apply to a single selected data item don't necessarily apply to multiple
     68 selected 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 
     81 <h2 id="checklist">Checklist</h2>
     82 
     83 <ul>
     84 <li>
     85 <p>Whenever your app supports the selection of multiple data items, make use of the contextual action
     86   bar (CAB).</p>
     87 </li>
     88 <li>
     89 <p>Reserve the long press gesture for selection exclusively. Don't use it to display traditional
     90   contextual menus.</p>
     91 </li>
     92 <li>
     93 <p>If you don't support multi-selection within a list, long press should do nothing.</p>
     94 </li>
     95 <li>
     96 <p>Plan the actions you want to display inside of a CAB in the same way you would plan the actions
     97   inside your app's action bar.</p>
     98 </li>
     99 </ul>
    100