I implemented it in fragment. I checked it on the Internet. Some people said they wanted to call back the ontouch event of the activity. Through the experiment, they can directly go to fragment. As follows:
My edittext is in scrollview. Because the ontouch event has been set in scrollview and is not thrown, you must listen to the ontouch event of scrollview.
Start and click somewhere else
When you click edittext
Code:
EditText:edtTxt_personal_nickname
ScrollView:sv_personal
First, set the edittext click event:
Click to trigger editable
Click Event:
Case R. Id. edttxt_personal_nickname: // You can edit the nickname settings to setedittexteditable (edttxt_personal_nickname, true); break;
Click an event from another location:
Sv_personal.setontouchlistener (New ontouchlistener () {@ overridepublic Boolean ontouch (view V, motionevent event) {// If the edit box gets the focus if (edttxt_personal_nickname.isfocused ()) {// The setedittexteditable (edttxt_personal_nickname, false); inputmethodmanager Imm = (inputmethodmanager) getactivity () is invisible to the editing box (). getsystemservice (context. input_method_service); Imm. hidesoftinputfromwindow (edttxt_personal_nickname.getwindowtoken (), 0) ;}return false ;}});
// Set whether the nickname can be edited private void setedittexteditable (edittext, Boolean value) {If (value) {edittext. setfocusableintouchmode (true); edittext. requestfocus (); edittext. setgravity (gravity. left);} else {edittext. setfocusableintouchmode (false); edittext. clearfocus (); edittext. setgravity (gravity. center );}}
Click edittext to edit it. Click other places to edit it.