I am using the following code to alternate between the done and next buttons on the keyboard depending on whether the checkbox is checked or not:
private OnClickListener checkBoxListener = new OnClickListener(){
@Override
public void onClick(View v) {
CheckBox cb = (CheckBox) findViewById(R.id.checkbox_referralCode);
EditText referralCode = (EditText) findViewById(R.id.referralCode);
EditText phoneText = (EditText) findViewById(R.id.phoneText);
if(cb.isChecked()) {
referralCode.setVisibility(View.VISIBLE);
phoneText.setImeOptions(0x00000005);
}
else
referralCode.setVisibility(View.GONE);
}
};
When the checkbox is not checked at first, the keyboard for phoneText displays done. When the checkbox is checked for the first time, the keyboard for phoneText now displays next. This is exactly what I wanted. However, The issue that I am facing with this is that when the user unchecks the checkbox after checking it first, the keyboard still displays next when I want it to show done. To correct this I added the following line to the else statement:
phoneText.setImeOptions(0x00000006);
Therefore, my new code looks like:
private OnClickListener checkBoxListener = new OnClickListener(){
@Override
public void onClick(View v) {
CheckBox cb = (CheckBox) findViewById(R.id.checkbox_referralCode);
EditText referralCode = (EditText) findViewById(R.id.referralCode);
EditText phoneText = (EditText) findViewById(R.id.phoneText);
if(cb.isChecked()) {
referralCode.setVisibility(View.VISIBLE);
phoneText.setImeOptions(0x00000005);
}
else {
referralCode.setVisibility(View.GONE);
phoneText.setImeOptions(0x00000006);
}
}
};
However, now the keyboard for phoneText only shows done even if the checkbox is either checked or not. What should I do to correct this?
Depends on the keyboard. I know for example that Swype will only check the imeoptions after a reload. One thing to try is to hide the keyboard and reopen it on this event.
You’re going to have a lot of troubles doing this in the end. The problem is that Android isn’t one keyboard- it has a framework that allows hot swapping of keyboards, but the API isn’t always well defined and keyboard devs have to guess on how things should be implemented. I don’t think in 2 years of developing keyboards I ever had an app try to change the imeOptions of a field after it was created. It may never have been done before, so it may be the framework isn’t even telling the keyboard that they’ve changed.