我有一个显示人员列表的RecyclerView,我添加了一个onClickListener来循环显示交通灯颜色。 所有这一切工作正常,但我试图在onClickListener中设置更新查询以更改数据库中的数据对该行:
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);
}
});
我在想我需要将数据库传递给适配器类?然后运行更新查询,但是有没有办法只对数据库执行更新而不通过它?