如何在RecyclerView中使用setOnFocusChangeListener? [英] How Do I Use setOnFocusChangeListener with RecyclerView?

查看:1117
本文介绍了如何在RecyclerView中使用setOnFocusChangeListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RecyclerView的适配器类中的onBindViewHolder()上具有以下内容:

I have the following on onBindViewHolder() in Adapter Class for RecyclerView:

holder.answerEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if(!hasFocus){

                        String answer = holder.answerEditText.getText().toString();

                        mDatasetAnswers.add(answer);

                    }
                }
            });

以上内容仅返回来自recyclerview中的第一个editText的输入.我可能做错了什么? 我希望它从recyclerview中的所有EditTexts返回文本.

The above only returns input from the first editText in the recyclerview. What could I be doing wrong? I would like it to return text from all EditTexts in the recyclerview.

推荐答案

之所以会发生这种情况,是因为一旦您单击了recyclerview中的任何Edit框,就会弹出键盘,因为调用了onbindview,并且焦点变为了第一个框. recyclerview,因为所有行都再次膨胀.

This happens because of the keyboard which pops up once you click on any Edit box in a recyclerview because onbindview is called and the focus changes to the first box in the recyclerview as all rows are reinflated again.

因此,在键盘弹出之前,请先监视聚焦增益并先进行操作.希望这会有所帮助.

Hence, monitor for on focus gain and do ur stuff first before keyboard pops up. Hope this helps.

这篇关于如何在RecyclerView中使用setOnFocusChangeListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆