![](/img/trans.png)
[英]recycler view hides message upward when keyboard is open / how to keep recycler View from scrolling when keyboard is on
[英]How can I keep the soft keyboard up when switching to the next EditText in a recycler view?
我面臨的問題是當用戶點擊鍵盤上的下一個按鈕時,程序應該專注於屏幕上的下一個EditText並保持鍵盤打開,直到屏幕上沒有更多啟用的EditTexts。 當沒有更多啟用的EditTexts時,鍵盤應該消失。
另一個問題是當屏幕上當前沒有可見的EditText時,在用戶選擇它之前它不會獲得焦點。
我嘗試使用輸入法管理器在EditText具有焦點時顯示鍵盤,並在沒有時隱藏。 如果沒有啟用更多啟用的EditTexts,鍵盤仍然存在。
final InputMethodManager imm = (InputMethodManager)
context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (variable.getType().equals("Value")) {
if (variable.getFormat().equals("Number") || variable.getFormat().equals("2Number")) {
viewHolder.inputValue.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
} else if(hasFocus && !viewHolder.inputValue.isEnabled()){
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
} else if (variable.getFormat().equals("Text")) {
viewHolder.messageText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
} else if(hasFocus && !viewHolder.inputValue.isEnabled()){
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
}
} else if (variable.getType().equals("Message")) {
viewHolder.messageText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
} else if(hasFocus && !viewHolder.inputValue.isEnabled()){
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});
} else {
//imm.hideSoftInputFromWindow(viewHolder.itemView.getWindowToken(), 0);
}
EditTexts存儲在recyclerview內的cardviews中。 每張卡都有一個可變類型。 單擊鍵盤上的下一個按鈕時,只有“值”和“消息”變量類型應該獲得焦點。
我希望用戶能夠通過單擊鍵盤上的下一個按鈕滾動RecyclerView中已啟用的EditTexts。 如果EditText不在屏幕上的視圖內,屏幕應向下滾動到它以獲得焦點。 此外,如果禁用EditText,它永遠不會獲得焦點。
重寫onEditorAction
方法,並為要保持鍵盤打開的每個editText返回true
。
edittext.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
//optional: you can run some logic here.
}
//return true to not hide the keyboard
return true;
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.