I am trying to display a dialog box in the hello Android Sudoku example but when I run the app nothing happens. In the game.java I check if the puzzle is solved like this
/******Check to see if the game is complete**/
public boolean isSolved()
{
for (int element : puzzle) {
if (element == 0) return false;
}
return true;
}
Then in the PuzzleView in the onKeyDown method i try to detect if isSolved is true and if it is display the dialog
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (game.isSolved() == true) {
Intent i = new Intent(mActivity, Congratulations.class);
getContext().startActivity(i);
} else {
Log.d(TAG, "onKeyDown: keycode=" + keyCode + ", event=" + event);
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
select(selX, selY - 1);
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
select(selX, selY + 1);
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
select(selX - 1, selY);
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
select(selX + 1, selY);
break;
case KeyEvent.KEYCODE_0:
case KeyEvent.KEYCODE_SPACE:
setSelectedTile(0);
break;
case KeyEvent.KEYCODE_1:
setSelectedTile(1);
break;
case KeyEvent.KEYCODE_2:
setSelectedTile(2);
break;
case KeyEvent.KEYCODE_3:
setSelectedTile(3);
break;
case KeyEvent.KEYCODE_4:
setSelectedTile(4);
break;
case KeyEvent.KEYCODE_5:
setSelectedTile(5);
break;
case KeyEvent.KEYCODE_6:
setSelectedTile(6);
break;
case KeyEvent.KEYCODE_7:
setSelectedTile(7);
break;
case KeyEvent.KEYCODE_8:
setSelectedTile(8);
break;
case KeyEvent.KEYCODE_9:
setSelectedTile(9);
break;
case KeyEvent.KEYCODE_ENTER:
case KeyEvent.KEYCODE_DPAD_CENTER:
game.showKeypadOrError(selX, selY);
break;
default:
return super.onKeyDown(keyCode, event);
}
return false;
}
return false;
}
I am learning java and Android development so please any help as to where I am going wrong will be much appreciated. If anyone needs more information please just ask and I will put it in an edit section for the question.