Getting values from RecyclerView EditText?

I think you are looking for a callback, which means whenever a number on one of the EditTexts is changed you want the total number change too. So first of all you need to add an interface,

OnEditTextChanged Interface

public interface OnEditTextChanged {
    void onTextChanged(int position, String charSeq);
}

Then you need too include this in the constructor of the adapter.

In the Adapter.java

private List<DataHolder> mDataSet;
private OnEditTextChanged onEditTextChanged;

public Adapter(List<DataHolder> myData, OnEditTextChanged onEditTextChanged) {
    mDataSet = myData;
    this.onEditTextChanged = onEditTextChanged;
}

In the onBindViewHolder of your Adapter you need to set a listener for text change and tell the fragment using onEditTextChanged object.

@Override
public void onBindViewHolder(ViewHolder holder, final int position) {
    holder.anameTxtView.setText(mDataSet.get(position).getDname());
    holder.abalanceTxtView.setText(mDataSet.get(position).getDbalance());

    holder.adepositEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            onEditTextChanged.onTextChanged(position, charSequence.toString());
        }

        @Override
        public void afterTextChanged(Editable editable) {}
    });
}

Add this array to your GroupCollectionFragment so you can save the values in your fragment and use them whenever you want them.

Integer[] enteredNumber = new Integer[1000];

change your constructor call in GroupCollectionFragment

mAdapter = new Adapter(holderList, new OnEditTextChanged() {
        @Override
        public void onTextChanged(int position, String charSeq) {
            enteredNumber[position] = Integer.valueOf(charSeq);
            updateTotalValue();
        }
    }); 

private void updateTotalValue() {
    int sum = 0;
    for (int i = 0; i < 1000; i++) {
        sum += enteredNumber[i];
    }

    totalValue.setText(String.valueOf(sum));
}

Let me know if you want the whole files. I wrote it and built the apk, it works just fine.


You can get value at action done of keyboard. all you need is to set

android:imeOptions="actionDone" in edit text. and then just use below code

 adepositEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                    if (actionId == EditorInfo.IME_ACTION_DONE) {
                        // Do whatever you want here

                        return true;
                    }
                    return false;

                });

Use TextChangedListener on EditText and save input in new HashMap with key as a id of order/unique key for row.

   adeposit.addTextChangedListener(new TextWatcher() {

   public void afterTextChanged(Editable s) {}

  public void beforeTextChanged(CharSequence s, int start,
                                int count, int after) {
  }

 public void onTextChanged(CharSequence s, int start,
                           int before, int count) {
  // Save value her in HashMap
  }
});

At the end get Values from HashMap.