EditBox register return key and click Blank return time input content cannot be written to the game

Source: Internet
Author: User

EditBox return key only hides the virtual keyboard, and can not write the input content to the game, nothing can be done, the experience is bad.

Cocos2d-x run apk on Android phone , there is a bunch of Java files (\runtime-src\proj.android\src\org\cocos2dx\lib)

1.

Locate cocos2dxeditboxdialog.java file

2. Import event mechanism

Import Android.view.View.OnClickListener; --After copying to 44 rows.

3. Implement Onclicklistener Interface

public class Cocos2dxeditboxdialog extends Dialog implements Onclicklistener{--line 56th

4. Registering events for the default layout

Layout.setonclicklistener (this); --Add to 158 lines

5. At this point, there should be a rewrite of the OnClick method

@Override

public void onClick (View v) {

// TODO auto-generated method stub

log.d ("shixc==============", "OnClick");

Cocos2dxhelper.setedittextdialogresult (cocos2dxeditboxdialog. This. Minputedittext. GetText (). toString ());

Cocos2dxeditboxdialog. This . Closekeyboard ();

Cocos2dxeditboxdialog. This . Dismiss ();

}

6, now Android simulation when we can click the blank exit Edit. But then register the listener event with the return key

Add the following code around 290 lines

public boolean dispatchkeyevent (keyevent event) {

System. out. println ("shixclog================" + event.getaction () + event. getKeyCode () + KeyEvent. keycode_back);

if (event. getKeyCode () = = KeyEvent. Keycode_back) {

Cocos2dxhelper.setedittextdialogresult (cocos2dxeditboxdialog. This. Minputedittext. GetText (). toString ());

Cocos2dxeditboxdialog. This. Closekeyboard ();

Cocos2dxeditboxdialog. This. Dismiss ();

return true;

}

return Super. Dispatchkeyevent (event); //

}

EditBox register return key and click Blank return time input content cannot be written to the game

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.