Heres my code:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("What's Your name?");
alert.setMessage("Seems like you're new here! What's your name?");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
This opens a Edit text with a ok and cancel button
How do i do this when you hit ok it will change the TextView's text to what ever is inside the box
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String newText = input.getText().toString();
textView.setText(newText);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.