java - TextEdit Text Input Issues in my game -


i working on android game , trying text input working. want prompt player enter or name , have name added high score list.

i trying through edittext can work if put code in oncreate method, not if call game loop.

the method using:

public static void getinput(context context) {     final alertdialog.builder alert = new alertdialog.builder(context);     final edittext input = new edittext(context);      alert.setview(input);     alert.setpositivebutton("ok", new dialoginterface.onclicklistener()      {         public void onclick(dialoginterface dialog, int whichbutton)          {             string value = input.gettext().tostring().trim();         }     });      alert.setnegativebutton("cancel",             new dialoginterface.onclicklistener()              {                 public void onclick(dialoginterface dialog, int whichbutton) {                     dialog.cancel();                 }             });     alert.show(); } 

if call gameloop game crashes , error:

01-26 06:33:21.413: error/androidruntime(6960): java.lang.runtimeexception: can't create handler inside thread has not called looper.prepare() 

i tried calling looper.prepare() , looper.loop(), , opened text input box, when closed box game sat on black screen , did not respond.

so, question is: doing wrong, , there easier way text input? game based off lunarlander example, using surfaceview.

any or suggestions appreciated. thank :)

hi smills: question should thread problem.any change on ui should down ui thread.you can use handler post intent prompt users . handler in gameloop function can post message,and same handler handlemessage on ui thread,then change ui.

the example this:

declare global variable:

handler mhandler;

your function(){

 message msg = message.obtain();  msg.what = flag ;  handler.post(msg); 

}


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -