gpt4 book ai didi

android - 编辑文本焦点更改监听器

转载 作者:行者123 更新时间:2023-11-29 02:31:41 24 4
gpt4 key购买 nike

我在 Recycler View 的一个项目中有两个编辑文本,我为每个编辑文本设置了一个焦点更改监听器。两者的输入类型都是文本。焦点更改监听器适用于第一个编辑文本,但对于第二个编辑文本,即使我单击键盘上的复选按钮(右下角),它也不会失去焦点。可能是什么问题?

holder.textView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
//textView.setGravity(Gravity.LEFT);
if(b){
holder.textView.setTextColor(getResources().getColor(R.color.TabYellow));
discreteScrollView.scrollToPosition(infiniteAdapter.getClosestPosition(position));
}
else {
Toast.makeText(getActivity(),"Input loose focus",Toast.LENGTH_SHORT).show();
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
holder.textView.setTextColor(getResources().getColor(R.color.white));
// textView.setGravity(Gravity.CENTER);
}
}
});
holder.newToDo.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean b) {
if(b){
discreteScrollView.scrollToPosition(infiniteAdapter.getClosestPosition(position));
}
else {
Toast.makeText(getActivity(),"Input loose focus",Toast.LENGTH_SHORT).show();
InputMethodManager imm = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
});`

最佳答案

虽然创建这种类型的布局不是一个好方法,但您仍然可以做的是添加键盘的 keyEventListner 并检查键的类型并插入将焦点传递到另一个位置的编辑文本的代码。

关于android - 编辑文本焦点更改监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49361191/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com