Possible methods for getting text input from user
Monkey Targets Forums/Android/Possible methods for getting text input from user
| ||
Hello all, I'm just wondering what the best way is to get the user's "name" for a high score chart. Is there a way I can retrieve the phone user's name from the system? (Although this assumes the user is the only one playing the game on their phone) Or is it better to allow the user to 'type' it in using a virtual keyboard - though I'm not sure how to retrieve text from that yet. |
| ||
I would vote for allowing the user to type it in using the virtual keyboard. If you only care about Android (my assumption, since you're posting here) here are some links to get you started: http://developer.android.com/reference/android/accounts/AccountManager.html The AccountManager class lets you ask the device for every conceivable type of accounts on it, so you can customize it towards for example, your favorite social site. http://www.androidsnippets.com/prompt-user-input-with-an-alertdialog Using an AlertDialog to prompt the user for input. Simple and straight forward Java example. Alternatively you could do both, and simply let the first name you got, be the default value for the second. |
| ||
Thanks FlameDuck - I will look more closely at the two links provided. |
| ||
Cool - Thanks FlameDuck, the second link works great :) Monkey Extern: Extern Function ShowAlertDialog:Void(title:String, message:String) = "diddy.showAlertDialog" Function GetInputString:String()="diddy.getInputString" Java code: import android.app.AlertDialog; import android.widget.EditText; import android.content.DialogInterface; import android.widget.EditText; class diddy { public static AlertDialog.Builder alert; public static EditText input; public static String inputString = ""; static void showAlertDialog(String title, String message) { alert = new AlertDialog.Builder(MonkeyGame.activity); alert.setTitle(title); alert.setMessage(message); // Set an EditText view to get user input input = new EditText(MonkeyGame.activity); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { inputString = input.getText().toString(); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); } static String getInputString() { return inputString; } } |
| ||
One issue (which I haven't tested yet) - what happens if the user enters non standard characters, for example if the language on their phone is not English, how will monkey handle that? |