我有一个绘图画布,其中有一个OnTouchListener
,我将其称为AlertDialog
。如何从对话框返回无效()?
在对话框中,我重置画布的底层数据(或不依赖于用户)。在回到画布dialog.cancel()
画布不重画,我希望它。
这意味着用户必须点击画布才能重画 - 不好!
由于该对话框异步运行,任何在画布中调用invalidate()
的操作都会在对话框返回已更改的基础数据之前完成。我做任何尝试无效或从对话框按钮代码内引用画布导致错误。我似乎在赶上22!
可以enyone给我建议吗?
对话框代码:
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) {
的Class 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();
`我做的任何尝试无效或从对话框按钮代码中引用画布导致错误` - 可能有助于向我们显示此代码和由此产生的错误。 – 2011-02-03 16:38:40