I have a menu option that allows the user to set the Bluetooth device name. Currently the dialogue does not actually display the current name of the device when selected. I want to present the user with the existing device name, in the editable text field, so that the user can see what the name of the device before changing it.
The current method looks like this.
private void changeName() {
if (D)
Log.d(TAG, "changeName");
// Open the alert dialog box
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Change Device 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 mButton) {
String mDevicename = input.getText().toString();
mBluetoothAdapter.setName(mDevicename);
Toast.makeText(getApplicationContext(),
"Update device name to: " + mDevicename,
Toast.LENGTH_SHORT).show();
}
});
alert.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int mButton) {
// Canceled.
}
});
alert.show();
}
I had to initialise a String variable with the value returned from calling the getName() method of the BluetoothAdapter class. I then passed this string variable to the setText() method of the AlertDialogue class.