0

I use RecyclerView and FirestoreRecyclerAdapter for displaying the list of available products to order. Also it will be per EditText for each row to input what amount of exact product do they want.

So, how do I get all of the fields from View.Holder(holder for my adapter) by clicking on a button

Image of app

Ben Shmuel
  • 1,819
  • 1
  • 11
  • 20
  • Please mention what you have tried so far – anoo_radha Nov 13 '19 at 16:39
  • Does this answer your question? [Saving EditText content in RecyclerView](https://stackoverflow.com/questions/31844373/saving-edittext-content-in-recyclerview) – Froyo Nov 13 '19 at 16:40
  • No, it didn't. First of all, I couldn't get how does it work. Also that is made with no FirestoreRecyclerAdapter. Do you have any other ideas? – Sardor Akayumov Nov 13 '19 at 16:52

1 Answers1

1

Suppose you have a list of Food model;

class Food{

    private String drinkName;
    private String drinkPrice;
    private String editTextValue;

    // getter setter
}

Add new variable/property in your model for editTextValue.

private String editTextValue;

Implement AddTextChangeListener in editText for listening content written in editText.

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
     vhItem.yourEditText.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {


                        }

                        @Override
                        public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
                                                   yourModel.setEditTextValue(editable.toString()); }

@Override
public void afterTextChanged(Editable editable) {
     yourModel.setEditTextValue(editable.toString());
    // setEditTextValue is function from getter setter
     }
                    });
    }

All editText value will be stored in your model list with their position.

iamnaran
  • 1,894
  • 2
  • 15
  • 24
  • Can I get value without textWatcher? When button is clicked? – Sardor Akayumov Nov 13 '19 at 17:31
  • No. You cannot. First, try implementing it inside Activity then try in recyclerview.Just assume an edit text is being watched, any changes will trigger it. And Adding value to the model on text changed or after text changed. – iamnaran Nov 13 '19 at 17:53
  • When the button is clicked, how do you access the list of models? (remember it's managed by a FirestoreRecyclerAdapter) – charles-allen Nov 13 '19 at 18:08
  • You can access your list from activity, using interface or you can just do adapter.yourArrayList if your list is public. – iamnaran Nov 20 '19 at 06:45