I have a 5-line EditText. I use checkbox to enable or disable the soft keyboard.
checkBoxSystem.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checkBoxSystem.isChecked()) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(textArea, InputMethodManager.SHOW_IMPLICIT);
textArea.setSelection(textArea.getText().length());
textArea.setMinLines(5);
textArea.setLines(5);
textArea.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
} else {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(textArea.getWindowToken(), 0);
textArea.setMinLines(5);
textArea.setLines(5);
textArea.setInputType(InputType.TYPE_NULL);
}
}
});
However, when I check it, the text turns into single line EditText. Then, when I uncheck it, it returns to his 5-lined position. Then I check the box again, EditText remains 5-lined. The other problem, when I click back, the soft keyboard disappears, but when I touch into EditText, it doesn't appear, so I need to click on the checkbox twice.
How can I prevent the EditText become single lined? And how can I make the keyboard activated, when I just click on the EditText, if the checkbox is checked already?
Aucun commentaire:
Enregistrer un commentaire