我有一个绘图画布,OnTouchListener
其中我称之为AlertDialog
.
在对话框中,我重置了画布的基础数据(或不取决于用户)。在使用画布返回画布时dialog.cancel()
不会重绘,我想要它。
这意味着用户必须单击画布才能使其重绘——不好!
invalidate()
因为对话框异步运行,所以在对话框返回更改的基础数据之前,画布中的任何调用都已完成。我从对话框按钮代码中使画布无效或引用画布的任何尝试都会导致错误。我似乎在第 22 阶段!
谁能给我建议?
对话代码:
case DIALOG_NEW_ID:
AlertDialog.Builder builder5 = new AlertDialog.Builder(this);
builder5.setMessage(" WARNING" +
"\nYour current game will be lost")
.setCancelable(false)
.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.setNegativeButton("Continue", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
cells.reset();
gameMode = 0;
dialog.cancel();
}
});
AlertDialog alert5 = builder5.create();
alert5.setOnDismissListener(new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface dialog) {
Log.d(TAG, "Dialog cancelled");// debug log entry
//myBoard.invalidate();
}
});
dialog = alert5;
break;
onTouch
画布中的对话框调用代码:
case MODE_SOLUTION:
break;
default:
showDialog(DIALOG_NEW_ID);
invalidate();
}// end switch
主类设置:
public class SudokuGame extends Activity {
static final int DIALOG_OPEN_ID = 0;
static final int DIALOG_INFO_ID = 1;
static final int DIALOG_FAIL_ID = 2;
static final int DIALOG_SAVE_ID = 3;
static final int DIALOG_NEW_ID = 4;
static final int MODE_ENTRY = 0;
static final int MODE_PLAY = 1;
static final int MODE_SHOW_ERRORS = 3;
static final int MODE_SOLUTION = 4;
final String TAG = "Game";
int gameMode;
SKU cells;
View myBoard;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_LEFT_ICON);
View myBoard = new NewBoard(this);
setContentView(myBoard);
setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher);
showDialog(DIALOG_OPEN_ID);
}// end onCreate
protected Dialog onCreateDialog(int id) {
嵌套在主类中的类 NewBoard:
class NewBoard extends View implements OnTouchListener{
int cW; // canvas width
int cH; // canvas height
int cellSize,textSize;
int boardX,boardY;
int runner, tX, tY,pX,pY,selectorX,selectorY;
int gap ;
int btn1X,btn1Y, selected;
int infoButtonX, infoButtonY,quitButtonX,quitButtonY;
boolean btn1Pressed, btn2Pressed, btn3Pressed, btn4Pressed, btn5Pressed;
String btn1,btn2,btn3,btn4,btn5;
public NewBoard(Context context){ // NewBoard Constructor
super(context);
this.setOnTouchListener(this);
cells = new SKU();
readStateStore();
}// end NewBoard Constructor
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
Rect textRect = new Rect();