I'm trying to pass the return of a method into my SQLite Database on the click of a button. The random unique roles should update an already existing column in a table. The trouble is, I have tried calling the method but I am getting errors. I have hit a wall and don't know how I would progress since I am relatively new to programming. This is my code for my activity class:
public class StartGame extends AppCompatActivity implements View.OnClickListener {
DatabaseHelper myDb;
Button btnRoles;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_startgame);
myDb = new DatabaseHelper(this);
btnRoles = (Button)findViewById(R.id.btnAssignRoles);
assignRoles();
}
public String RandomNumber() {
List<String> roles = Arrays.asList("Mafia", "Mafia", "Angel", "Detective", "Civilian", "Civilian", "Civilian");
Collections.shuffle(roles);
Random rand = new Random();
int i = 0;
while (i < 7) {
roles.get(i);
i++;
}
return roles.get(i);
}
public void assignRoles() {
btnRoles.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
{
}
}
}
);
}
@Override
public void onClick(View v) {
}
}
I have this in my database helper class so far for this method:
public boolean updateRole(String role){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL_ROLE, role);
db.update(TABLE_NAME, contentValues, "Role =?", new String[] {role});
return true;
}
My question is, what should I look at to progress this? It's driving me crazy because I can't figure it out and materials online aren't being any help. Any help would be greatly appreciated!
Aucun commentaire:
Enregistrer un commentaire