ListView focus, androidlistview focus
If the view of a single Item in ListView contains a view such as checkbox and button, the ListView. setOnItemClickListener is invalid,
The event is captured by the View, and ListView cannot capture and process the event.
Solution:
Method 1:
Add android: focusable = "false" to the view corresponding to the checkbox and button"
Android: clickable = "false" android: focusableInTouchMode = "false"
Focusable is the key
Call getSelectedItemPosition () from OnClickListener. Click and selection are irrelevant. Selection is operated through D-pad or trackball. Click is usually a Click operation.
Method 2:
In your own getView
ConvertView = mInflater. inflate (R. layout. list_item_text, null );
ConvertView. setClickable (true );
ConvertView. setOnClickListener (clickListener );
PublicOnClickListenerMyClickListener=NewOnClickListener(){
PublicVoidOnClick(ViewV){
// Code to be written to handle the click event
}
};
If your custom ListViewItem contains a Button or Checkable subclass control, the default focus is handed over to the child control, and the basis for the ListView Item to be selected is that it can get the Focus, in other words, we can set the focusable attribute of all controls contained in items in ListView to false. In this way, the items in ListView will automatically obtain the Focus permission and be selected, in this case, the onItemClick () method in onItemClickListener is returned. However, setting the focusable attribute of the sub-Control of 'itemlayout of ListView to 'false' is a little complicated. We can set its android through the root control of 'itemlayout: descendantFocusability = "blocksDescendants". In this way, Item Layout shields all child controls from obtaining the Focus permission. You do not need to reset the focusable attribute for each control in Item Layout, in this way, you can smoothly respond to the onItenClick () method in onItemClickListener.