Home | History | Annotate | Download | only in ui
      1 page.title= 
      2 parent.title= 
      3 parent.link=index.html
      4 @jd:body
      5 
      6 <div id="qv-wrapper">
      7 <div id="qv">
      8   <h2>  </h2>
      9   <ol>
     10     <li><a href="#EventListeners"> </a></li>
     11     <li><a href="#EventHandlers"> </a></li>
     12     <li><a href="#TouchMode"> </a></li>
     13     <li><a href="#HandlingFocus"> </a></li>
     14   </ol>
     15 
     16 </div>
     17 </div>
     18 
     19 <p>Android          . 
     20      ,       
     21     .      .</p>
     22 
     23 <p>           UI      
     24       .         Android  
     25  .   (: )   
     26   <code>onTouchEvent()</code>  .      
     27   .         
     28     .     
     29            .   
     30   <a href="#EventListeners"> </a> ,  UI       .</p>
     31 
     32 <p>            ,   
     33            . 
     34  {@link android.widget.Button}
     35          .  ,       
     36 <a href="#EventHandlers"> </a>    .</p>
     37 
     38 
     39 <h2 id="EventListeners"> </h2>
     40 
     41 <p>  {@link android.view.View}     ,    
     42   .      UI         
     43 Android   .</p>
     44 
     45 <p>       .</p>
     46 
     47 <dl>
     48   <dt><code>onClick()</code></dt>
     49     <dd>{@link android.view.View.OnClickListener}  . 
     50      
     51 (   ),           
     52  ""      .</dd>
     53   <dt><code>onLongClick()</code></dt>
     54     <dd>{@link android.view.View.OnLongClickListener}  . 
     55       (   ), 
     56           
     57  ""      ( ).</dd>
     58   <dt><code>onFocusChange()</code></dt>
     59     <dd>{@link android.view.View.OnFocusChangeListener}  . 
     60               .</dd>
     61   <dt><code>onKey()</code></dt>
     62     <dd>{@link android.view.View.OnKeyListener}  . 
     63                 .</dd>
     64   <dt><code>onTouch()</code></dt>
     65     <dd>{@link android.view.View.OnTouchListener}  . 
     66           ,  
     67 ,       (  ) .</dd>
     68   <dt><code>onCreateContextMenu()</code></dt>
     69     <dd>{@link android.view.View.OnCreateContextMenuListener}  . 
     70        ( " " ). 
     71 <a href="{@docRoot}guide/topics/ui/menus.html#context-menu"></a>
     72         .</dd>
     73 </dl>
     74 
     75 <p>       .     
     76            . 
     77      
     78  <code>View.set...Listener()</code>   (: 
     79 <code>{@link android.view.View#setOnClickListener(View.OnClickListener) setOnClickListener()}</code> 
     80    {@link android.view.View.OnClickListener OnClickListener}  ).</p>
     81 
     82 <p>    -     . </p>
     83 
     84 <pre>
     85 // Create an anonymous implementation of OnClickListener
     86 private OnClickListener mCorkyListener = new OnClickListener() {
     87     public void onClick(View v) {
     88       // do something when the button is clicked
     89     }
     90 };
     91 
     92 protected void onCreate(Bundle savedValues) {
     93     ...
     94     // Capture our button from layout
     95     Button button = (Button)findViewById(R.id.corky);
     96     // Register the onClick listener with the implementation above
     97     button.setOnClickListener(mCorkyListener);
     98     ...
     99 }
    100 </pre>
    101 
    102 <p>OnClickListener        .
    103           . :</p>
    104 <pre>
    105 public class ExampleActivity extends Activity implements OnClickListener {
    106     protected void onCreate(Bundle savedValues) {
    107         ...
    108         Button button = (Button)findViewById(R.id.corky);
    109         button.setOnClickListener(this);
    110     }
    111 
    112     // Implement the OnClickListener callback
    113     public void onClick(View v) {
    114       // do something when the button is clicked
    115     }
    116     ...
    117 }
    118 </pre>
    119 
    120 <p>  <code>onClick()</code>  
    121                .     
    122 .       ,   .</p>
    123 <ul>
    124   <li><code>{@link android.view.View.OnLongClickListener#onLongClick(View) onLongClick()}</code> - 
    125               . 
    126  , <em></em>         
    127 <em></em>     /    
    128 -      .</li>
    129   <li><code>{@link android.view.View.OnKeyListener#onKey(View,int,KeyEvent) onKey()}</code> - 
    130               .
    131      , <em></em>         
    132 <em></em>     /    
    133 -      .</li>
    134   <li><code>{@link android.view.View.OnTouchListener#onTouch(View,MotionEvent) onTouch()}</code> - 
    135          .    
    136            .  ''     <em></em> , 
    137          
    138     .         
    139  (:     ''   ).</li>
    140 </ul>
    141 
    142 <p>           .       
    143        . (  ) 
    144    ,  <code>{@link android.view.View#dispatchKeyEvent(KeyEvent)
    145 dispatchKeyEvent()}</code>       .      ,     <code>{@link android.app.Activity#onKeyDown(int,KeyEvent) onKeyDown()}</code> 
    146 
    147 <code>{@link android.app.Activity#onKeyUp(int,KeyEvent) onKeyUp()}</code>    .</p>
    148 
    149 <p>,             
    150 .       .  ,     .  
    151       
    152 <code>{@link android.app.Activity#onKeyDown(int,KeyEvent) onKeyDown()}</code>   <strong></strong>.    
    153   UI    .       
    154  . ,            
    155   . , {@link android.view.inputmethod.EditorInfo#IME_ACTION_DONE}          
    156       UI      .    
    157     ,         .</p>
    158 
    159 <p class="note"><strong>:</strong> Androids    ,      
    160      . ,     <em></em>   
    161           
    162      .  <em></em>         .</p>
    163 
    164 
    165 <h2 id="EventHandlers"> </h2>
    166 
    167 <p>      ,       
    168      .
    169 <a href="{@docRoot}guide/topics/ui/custom-components.html"> 
    170  </a>             . 
    171     .</p>
    172 <ul>
    173   <li><code>{@link  android.view.View#onKeyDown}</code> -     .</li>
    174   <li><code>{@link  android.view.View#onKeyUp}</code> -   ''   .</li>
    175   <li><code>{@link  android.view.View#onTrackballEvent}</code> -     .</li>
    176   <li><code>{@link  android.view.View#onTouchEvent}</code> -      .</li>
    177   <li><code>{@link  android.view.View#onFocusChanged}</code> -      .</li>
    178 </ul>
    179 <p>         .     , 
    180           . ,        , 
    181     .</p>
    182 <ul>
    183   <li><code>{@link  android.app.Activity#dispatchTouchEvent(MotionEvent)
    184     Activity.dispatchTouchEvent(MotionEvent)}</code> -   {@link 
    185     android.app.Activity}            .</li>
    186   <li><code>{@link  android.view.ViewGroup#onInterceptTouchEvent(MotionEvent)
    187     ViewGroup.onInterceptTouchEvent(MotionEvent)}</code> -   {@link
    188     android.view.ViewGroup}          .</li>
    189   <li><code>{@link  android.view.ViewParent#requestDisallowInterceptTouchEvent(boolean)
    190     ViewParent.requestDisallowInterceptTouchEvent(boolean)}</code> -  
    191     <code>{@link 
    192     android.view.ViewGroup#onInterceptTouchEvent(MotionEvent)}</code>        .</li>
    193 </ul>
    194 
    195 <h2 id="TouchMode"> </h2>
    196 <p>
    197           , 
    198   (: )        
    199     .        
    200       ,      
    201      .   " "     
    202   . 
    203 </p>
    204 <p>
    205     ,       
    206  .    
    207 {@link android.view.View#isFocusableInTouchMode}      .       . 
    208                
    209 -   .
    210 </p>
    211 <p>
    212           
    213       .     
    214    ,    .
    215 </p>
    216 <p>
    217       (   ). 
    218    
    219 {@link android.view.View#isInTouchMode}        .
    220 </p>
    221 
    222 
    223 <h2 id="HandlingFocus"> </h2>
    224 
    225 <p>       . 
    226     ,         
    227    .      
    228 <code>{@link android.view.View#isFocusable()}</code>   .        
    229 <code>{@link android.view.View#setFocusable(boolean) setFocusable()}</code> .     , 
    230   <code>{@link android.view.View#isFocusableInTouchMode()}</code>        . 
    231  <code>{@link android.view.View#setFocusableInTouchMode(boolean) setFocusableInTouchMode()}</code>  .
    232 </p>
    233 
    234 <p>          
    235 .          
    236  .  ,     XML  
    237     .
    238 <var>nextFocusDown</var>, <var>nextFocusLeft</var>, <var>nextFocusRight</var>, 
    239 <var>nextFocusUp</var>.        <em></em>   
    240 .    
    241 <em> </em>  ID  . :</p>
    242 <pre>
    243 &lt;LinearLayout
    244     android:orientation="vertical"
    245     ... >
    246   &lt;Button android:id="@+id/top"
    247           android:nextFocusUp="@+id/bottom"
    248           ... />
    249   &lt;Button android:id="@+id/bottom"
    250           android:nextFocusDown="@+id/top"
    251           ... />
    252 &lt;/LinearLayout>
    253 </pre>
    254 
    255 <p>            , 
    256      .          
    257 . <var>nextFocusUp</var> ( )       
    258    .</p>
    259 
    260 <p> UI        (  ), 
    261    <code>android:focusable</code> XML  . 
    262   <var></var> .           
    263   . <code>android:focusableInTouchMode</code>  .</p>
    264 <p>    , <code>{@link android.view.View#requestFocus()}</code> .</p>
    265 <p>   (        ), 
    266 <code>{@link android.view.View.OnFocusChangeListener#onFocusChange(View,boolean) onFocusChange()}</code>  . 
    267   <a href="#EventListeners"> </a>    .</p>
    268 
    269 
    270 
    271 <!--
    272 <h2 is="EventCycle">Event Cycle</h2>
    273    <p>The basic cycle of a View is as follows:</p>
    274    <ol>
    275     <li>An event comes in and is dispatched to the appropriate View. The View
    276     handles the event and notifies any listeners.</li>
    277     <li>If, in the course of processing the event, the View's bounds may need
    278     to be changed, the View will call {@link android.view.View#requestLayout()}.</li>
    279     <li>Similarly, if in the course of processing the event the View's appearance
    280     may need to be changed, the View will call {@link android.view.View#invalidate()}.</li>
    281     <li>If either {@link android.view.View#requestLayout()} or {@link android.view.View#invalidate()} were called,
    282     the framework will take care of measuring, laying out, and drawing the tree
    283     as appropriate.</li>
    284    </ol>
    285    
    286    <p class="note"><strong>Note:</strong> The entire View tree is single threaded. You must always be on
    287    the UI thread when calling any method on any View.
    288    If you are doing work on other threads and want to update the state of a View
    289    from that thread, you should use a {@link android.os.Handler}.
    290    </p>
    291 -->
    292