我有一個繪圖畫布,其中有一個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