Thursday, September 1, 2011

[android-developers] Alert input must show the keyboard.

Hi all...

I have this code to show an alert input.
When a user click on some object I launch this alert input to let the
user to input some data.

To do it I use this code.

void alertInputStr(String title, String message, int
numeroCampoEditabile) {
AlertDialog.Builder alertI = new AlertDialog.Builder(this);
final int num = numeroCampoEditabile;
alertI.setTitle(title);
alertI.setMessage(message);
input = new EditText(this);
alertI.setView(input);
alertI.setPositiveButton("Ok", new
DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int
whichButton) {
Editable value = input.getText();
String valInput;
try {
valInput = value.toString();
} catch (Exception e) {
valInput = "";
}
switch (num) {
case 1:
Home.to = valInput;
instance.setContentView(new
SendMail(instance));
break;
}
}
});
alertI.setNegativeButton("Cancel", new
DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int
whichButton) {
}
});
alertI.show();
}

This code displays an alert with a textbox, user can tap on the
textbox to enter the desiderd value.
The problem is that in this way user needs to tap two times to enter
the text.
Is it possible to display the alert input with the keyboard opened,
without the needs to tap a second time to open the keyboard?

Thanks.

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment