I have a recyclerview with a card and spinners in it, the values selected in the spinner I need to send it to the next activity to calculate estimated price. I have a button in the activity which is not of the recyclerview, that takes me to next activity where I need the values. So when I click this button I need it to collect the data and send it to next activity, how can I achieve that.
I have attached a picture. RED ARROW(data i need in next activity), BLUE ARROW(button press which takes me to next activity)
I'm using this method to read the values
findMerchantTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < totalCards; i++) {
Spinner printColorSpinner = mRecyclerView.findViewHolderForLayoutPosition(i).itemView.findViewById(R.id.printColorSpinner);
Spinner printSidesSpinner = mRecyclerView.findViewHolderForAdapterPosition(i).itemView.findViewById(R.id.printSidesSpinner);
Spinner printSizeSpinner = mRecyclerView.findViewHolderForAdapterPosition(i).itemView.findViewById(R.id.paperSizeSpinner);
Spinner pagesSpinner = mRecyclerView.findViewHolderForAdapterPosition(i).itemView.findViewById(R.id.pagesSpinner);
Spinner orientationSpinner = mRecyclerView.findViewHolderForAdapterPosition(i).itemView.findViewById(R.id.orientationSpinner);
Spinner bindingTypeSpinner = mRecyclerView.findViewHolderForAdapterPosition(i).itemView.findViewById(R.id.bindingTypeSpinner);
MaterialTextView copiesTextView = mRecyclerView.findViewHolderForAdapterPosition(i).itemView.findViewById(R.id.copiesNumberText);
String color = printColorSpinner.getSelectedItem().toString().trim();
String sides = printSidesSpinner.getSelectedItem().toString().trim();
String size = printSizeSpinner.getSelectedItem().toString().trim();
String pages = pagesSpinner.getSelectedItem().toString().trim();
String orientation = orientationSpinner.getSelectedItem().toString().trim();
String bindingType = bindingTypeSpinner.getSelectedItem().toString().trim();
String totalCopies = copiesTextView.getText().toString().trim();
}
}
});
But when i becomes 2, findViewHolderForLayoutPosition returns NullPointerException. I searched and got to know that the views are recycled and only the views that are laid out on screen will be readable.
What will be the alternative to get these values? Thanks!