1. in another case where the OnItemClickListener of ListView is not triggered, for example, in an ItemView, only one TextView is located at the leftmost, and its right side is a blank area without any controls, when you click the area on the right, OnItemClickListener is not triggered. When you click the area where TextView is located, this event is triggered. Check whether there is no View control in the blank part on the right of the execution process of this event. That is to say, although you click this part with your finger, the view does not get the focus, android event triggers are searched from the top-level view layer by layer. If a view gets the focus, it is handed over to the view for processing. If not, it is handed over to the activity for processing. The click event and the touch event are transmitted in different ways. They are used to add listening events for touch and itemClick to ListView at the same time. Their trigger order is as follows: actionDown -------- action up --------- onItemClick their execution process is: first according to the touch event processing process, and then click the event processing, this shows that when the user presses the screen, two events are generated. One is a touch event and the other is a click event, which is added to the queue of the main thread. You touch the screen with your fingers and scroll the ListView. The click operation is also performed, but the result is that only the touch event is triggered and the click event is not triggered. 2. Relationship between ListView's focus acquisition and ItemView's focus retrieval 2.1 does not get the focus of ListView. Can ItemView get the focus? You can set the android: focusable = "true" android: focusableInTouchMode = "true" attribute of ItemView to get the focus of ItemView in Touch mode. By default, ItemView in Touch mode, menus and other controls cannot obtain the focus. Only after ListView obtains the focus can ItemView obtain the focus. Tutorial 1: Set the focusable attribute of ListView to true, android: focusable = "true" android: focusableInTouchMode = "true" for ItemView, and customize the touch event listener, override onTouch method public boolean onTouch (View v, MotionEvent event) {switch (event. getAction () {case MotionEvent. ACTION_DOWN: // clear (); int x = (int) event. getX (); int y = (int) event. getY (); int position = mListView. pointToPosition (x, y); int firstVisiblePosition = mListView. getFirst VisiblePosition (); view = mListView. getChildAt (position-firstVisiblePosition); if (view = null) return false; if (view. isFocusable () {Log. I (tag, "ItemView is focusable");} if (view. isFocusableInTouchMode () {Log. I (tag, "ItemView is focusable in touchMode");} if (view. isInTouchMode () {Log. I (tag, "device is in touch mode. ");} if (mListView. isFocusable () {Log. I (tag, "mListView is focusable");} if (MListView. isFocusableInTouchMode () {Log. I (tag, "mListView isFocusableInTouchMode in touchMode");} if (view. isFocused () {Log. I (tag, "ItemView have get focus");} if (mListView. isFocused () {Log. I (tag, "mListView have get focus");} if (view. isPressed () {Log. I (tag, "ItemView have get pressed");} break; case MotionEvent. ACTION_UP: if (view = null) return false; Log. I (tag, "OnTouchListener: up is w Orking "); if (view. isFocused () {Log. I (tag, "ItemView have get focus");} break; default: break;} return false;} the print result is: itemView is focusable in touchMode device is in touch mode. mListView is focusable mListView isFocusableInTouchMode in touchMode mListView have get focus OnTouchListener: up is working triggers the touch event when you touch the screen, but only the ListView gets the focus, but the itemView does not get the focus, description: itemView is in the default format In the touchmode mode, you can get the focus in real time. In fact, the focusable attribute of ListView is not set to true in real time, and the focus can also be obtained, so how can we get the focus of ItemView? There are two methods: The requestFocus () method of the View class, the requestChildFocus (child, focused) method of the ListView, And the requestFocusFromTouch () method () method, which is a method of the View class. ListView inherits this method. We asked itemView to call the requestFocus () method or the requestFocusFromTouch () method. At this time, itemView obtains the focus, but ListView does not obtain the focus. This indicates that only one view can obtain the focus. Remove the android: focusableInTouchMode = "true" attribute of itemView and call the requestFocusFromTouch () method to force itemViw to obtain the focus. ListView still does not get the focus. Conclusion: 1. when you use the navigation key to scroll up or down, the android framework automatically sets the view to focus (after the focus is obtained, it is highlighted). However, when you touch the screen by hand, the view does not need to automatically obtain the focus. That is to say, when a user clicks a control on the screen, the control does not need to automatically obtain the focus, because the user knows which control he is operating, when the user touches the screen of the mobile phone, it will enter the touch mode. 2. in touch mode, some controls do not automatically obtain the focus, but some controls do. You can use isFocusableInTouchMode () to check whether the control can obtain the focus in touch mode, textView cannot obtain the focus by default. ListView can obtain the focus by default, and EditText and other text editing controls can all be used. By setting android: focusableInTouchMode = "true", it seems that the view control can get the focus, but it does not actually get the focus of the veiw control. You also need to manually call the requestFocusFromTouch () method or requestFocus () method to obtain the focus. We recommend that you use the requestFocusFromTouch () method. You do not need to set android: focusableInTouchMode = "true" in real time, and you can also force the control to get focus. 3. the method for obtaining the control in ListView that obtains the focus is mListView. findFocus (); mListView. getFocusedChild (); 4. the setItemsCanFocus (true) method of ListView does not allow ItemView to obtain focus in touch mode. It only indicates that the view created by ListAdapter can contain items that can obtain focus. This statement is incorrect when a rolling event occurs after a touch event. experiment shows that the onScroll method is executed before the touch event, and this method is triggered every time you touch the screen, then, the touch event is triggered. In addition, when we first enter the list interface, the onScroll method is also called multiple times. The first time it is called when the onCreate method is executed, the page has not yet been generated. Therefore, the visibleItemCount parameter is 0, and the page is displayed after several calls. visibleItemCount is also assigned the number of items displayed on the page, the display is incomplete. There are almost two calls, and the two calls are different. Let's look at the differences between the three calls. When you touch a certain item on the screen by hand, this method will also be triggered first, then, the touch event can be rewritten by the onTouch method. When the user clicks the screen, the itemView gets the focus and changes color, but there are two problems: 1. if the ListView displays multiple pages, you can see that another ItemViw on each page gets the focus. Why? Speculation: The second eroded convertView of the getView method in the Adapter is reused. It is estimated that the veiw that obtains the focus is reused when a new page is generated. Here we also need to look at source code 2. when you scroll to a non-first page, the triggered screen does not allow the ItemView where the triggering point is located to get the focus? The index parameter of the getChildAt (int index) method of ListView is different from the position parameter of the getView method of the Adapter. Each interface displays several items, create an index that ranges from 0 to the number displayed on the page. For example, if eight records are displayed on a screen, the index is 0-7. If you flip the page, a similar index will still be created, therefore, the index of the item at the trigger point on the screen should be calculated. Int x = (int) event. getX (); int y = (int) event. getY (); int position = mListView. pointToPosition (x, y); int firstVisiblePosition = mListView. getFirstVisiblePosition (); view = mListView. getChildAt (position-firstVisiblePosition );