
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

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