Android ListView is good for simple list display, but when it comes to manipulating the ListView, you encounter a variety of problems. For example, save the checkbox state and the item reuse conflict, encountered the focusable control such as button, Edxttext and so on the ListView itself and the Click event Conflict. For the latter, the reason is not studied here, only solutions are provided.
If the ListView is the only button that will rob the focus of the control, the best advice is to switch the button directly to TextView, directly avoiding the focus problem.
If some product managers require complex operations in the ListView item, such as input, radio check, and so on, provide a simple response to the button control at the same time, and respond to the Onitemclick event of the ListView: Add the Ontouch event for the entire ListItem, and in the event set all the controls that may be grabbing focus to the non-focusable focus. This guarantees that the Liistview responds to the Onitemclick event, sets the Ontouch event for each control that might have the focus, sets it to the focusable focus, and then loses focus to the button, such as when the finger is away.
The specific code is as follows
@Overridepublic Boolean OnTouch (View view, Motionevent motionevent) {if (view instanceof EditText) {//edittext is set to Focusable
edittext EditText = (EditText) view; Edittext.setfocusable (true); Edittext.setfocusableintouchmode (True);} else if (view instanceof Button | | view instanceof RadioButton) {//set to focusable, set as non-focusable if when finger is lifted (motionevent.getaction () = = Motion EVENT.ACTION_UP) {view.setfocusable (false); View.setfocusableintouchmode (false);} Else{view.setfocusable (True); View.setfocusableintouchmode (True);}} else {Viewholder holder = (viewholder) view.gettag ();// Set the Setfocusable and Setfocusableintouchmode methods of all controls that may have the focus to falsesetedittextfoucsablefalse (holder);} return false;}
Note: If there is edittext, in order to ensure that the input method normal pop-up, you need to set android:windowsoftinputmode= "Adjustpan"
Android ListView Focus Event conflict problem and resolution