I have rendered a list of items in a recyclerView
. When i clicked the Floating action Button, i want to pass the items which have been selected along with the quantity that they have input in the EditText
. Could anyone give me an example
Asked
Active
Viewed 2,313 times
-1

Boris Ningthoujam
- 25
- 5
-
please share the code – Tanveer Munir Jan 28 '19 at 06:42
-
Possible duplicate of [Saving EditText content in RecyclerView](https://stackoverflow.com/questions/31844373/saving-edittext-content-in-recyclerview) – Shubham AgaRwal Jan 28 '19 at 06:43
-
it's not just saving editText.it's saving multiple editText as well as selected item – Boris Ningthoujam Jan 28 '19 at 09:22
2 Answers
0
Use edit text text changed listener to get the values and store the values as an array.
class MyViewHolder extends RecyclerView.ViewHolder{
protected EditText editText;
public MyViewHolder(View itemView) {
super(itemView);
editText = (EditText) itemView.findViewById(R.id.editid);
editText.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) {
editModelArrayList.get(getAdapterPosition()).setEditTextValue(editText.getText().toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
}

Praveen
- 93
- 1
- 7
0
You can do this by using some extra variables in model class
For example:-
class Model{
private boolean isChecked; // for checkbox click set this to true and notifyDataSetChanged()
private String editTextValue: // call text watcher with editext change and set this variable after every text change in edit text
}
View Holder class:-
class MyViewHolder extends RecyclerView.ViewHolder{
protected EditText editText;
protected CheckBox checkBox;
public MyViewHolder(View itemView) {
super(itemView);
editText = (EditText) itemView.findViewById(R.id.editid);
checkBox = (CheckBox) itemView.findViewById(R.id.checkbox);
editText.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) {
editModelArrayList.get(getAdapterPosition()).setEditTextValue(editText.getText().toString());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
if (isChecked) {
editModelArrayList.get(getAdapterPosition()).setChecked(true);
} else {
editModelArrayList.get(getAdapterPosition()).setChecked(false);
}
});
}
All these explanation in code is performed inside adapter and then access these variables by getter methods at the time of onClick() of fab button. For example:-
void onFabButtonClick(View v){
for(Object ob: yourList){
if(ob.isChecked())
{ // store checked data here in any list and pass any where you want
}
}
// pass data from here after store
}

DeePanShu
- 1,236
- 10
- 23
-
could you please share your implementation with an example application – Boris Ningthoujam Jan 28 '19 at 10:07