Click edittext to edit it. Click other places to edit it.

Source: Internet
Author: User
Tags call back

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.