0

I made SQL database and manage to populate RecyclerView with inserted data. For the next part of the project, I need to highlight selected item (changeBackgroundColor etc) in RecyclerView, after I inserted a value for that chosen item.

onBindViewHolder method:

@Override
public void onBindViewHolder(MenuViewHolder holder, final int position) {
    final Food singleFood = foodList.get(position);

    holder.foodName.setText(singleFood.getName());
    holder.enterGram.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            editTaskDialog(singleFood);
        }
    });
}

In editTaskDialog() method I called AlertDialog with one EditText widget and setPositiveButton(), setNegativeButton(). So after the user choose one item from RecyclerView and enters the value in that EditText and touches setPositiveButton(), that selected item must be highlighted, because in next activity I need to operate with that selected items and entered values. setPositiveButton() will call update method and save that value in SQL database (that part is done).

I understand that I need to check selected item with a row in SQL database (entered value). In case that they match or equal I need to call setBackgroundColor() or some similar method. I'm just not sure how to do that correctly.

After that, I hope I will somehow figure out how to manipulate with these selected items. But that is not part of this question.

Any suggestions will be appreciated. Let me know if u are interested in some more code, to better understand my question.

akhilesh0707
  • 6,709
  • 5
  • 44
  • 51
odin_allfather
  • 29
  • 2
  • 11

0 Answers0