7

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);

                    }
                }
            });

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.

ZNZ MW
  • 75
  • 1
  • 4

2 Answers2

1

Try to add these lines:

holder.answerEditText.setFocusable(true);
holder.answerEditText.setFocusableInTouchMode(true);

With these lines you make sure that the component can capture the focus.

Daniel RL
  • 353
  • 1
  • 12
0

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.

Khader
  • 16
  • 2