0

I have a RecyclerView which displays a list of people, I have added an onClickListener to cycle through a traffic light colours. All this works fine, but I am trying to set an update query within the onClickListener to change the data within the database against that row:

    String name = pCursor.getString(pCursor.getColumnIndex(PlayerDetails.PlayerTableEntry.COLUMN_PLAYER_NAME));
    String number = pCursor.getString(pCursor.getColumnIndex(PlayerDetails.PlayerTableEntry.COLUMN_PLAYER_NUMBER));
    Long id = pCursor.getLong(pCursor.getColumnIndex(PlayerDetails.PlayerTableEntry._ID));
    holder.playerView.setTag(id);
    holder.itemView.setTag(id);
    holder.playerView.setText(name + "\n" + number);

    int answer = pCursor.getInt(pCursor.getColumnIndex(PlayerDetails.PlayerTableEntry.COLUMN_IS_PLAYING));

    if (answer == 0) {
        holder.redView.setVisibility(View.VISIBLE);
        holder.greenView.setVisibility(View.INVISIBLE);
        holder.amberView.setVisibility(View.INVISIBLE);

    } else if (answer == 1) {
        holder.greenView.setVisibility(View.VISIBLE);
        holder.amberView.setVisibility(View.INVISIBLE);
        holder.redView.setVisibility(View.INVISIBLE);

    } else if (answer == 2) {
        holder.amberView.setVisibility(View.VISIBLE);
        holder.redView.setVisibility(View.INVISIBLE);
        holder.greenView.setVisibility(View.INVISIBLE);
    }

    holder.allTheViews[0].setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {                                                         
            ManualPlayingChange.notToPlaying(holder);
        }
    });

    holder.allTheViews[1].setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {                 
            ManualPlayingChange.notToPlaying(holder);
        }
    });

    holder.allTheViews[2].setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {                 
            ManualPlayingChange.notToPlaying(holder);
        }
    });

I am thinking I need to pass the database into the adapter class? and then run an update query, but is there a way just perform an update on the database without having the pass it through?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

0 Answers0