androidandroid-recyclerviewnotifydatasetchanged

Refresh only one parameter of list item in recycler view item contains increment + decrement + spinner


I want to refresh only one parameter of list item where list item contains provision to increase or decrease the value and spinner.

When I select the spinner value and increase and refresh item by notify datachange() the value of spinner goes on default each time I increase or decrease.

How to tackle this issue?


Solution

  • finally got the solution. i just take one Boolean isFirstTimeInflate = true; in adapter when it is first time inflate all the views. when item position == list.size(); make isFirstTimeInflate = false;

    @Override
        public void onBindViewHolder(final CardViewHolder holder, final int position) {
            final Category category = categories.get(position);
    
            holder.plus.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EventBus.getDefault().post(new ActionEvent(category, position, true, false));
                }
            });
    
            holder.minus.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EventBus.getDefault().post(new ActionEvent(category, position, false, true));
                }
            });
    
            if (isFirstTimeInflate) {
                value.setAdapter(new SpinnerAdapter(context, R.layout.points_spinner_row, category.getAvailableCards()));
                value.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    @Override
                    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                        category.setValue(category.getAvailableCards().get(position));
                    }
    
                    @Override
                    public void onNothingSelected(AdapterView<?> parent) {
    
                    }
                });
            }
    
            count.setText(category.getCount() + "");
            if (position == categories.size()-1) {
                isFirstTimeInflate = false;
            }
        }