0
我想在點擊畫布5秒後輸出彈出對話框。不過,當我點擊畫布後,我的對話框立即出現。我該如何解決這個問題?Android:如何在點擊畫布一段時間後顯示彈出對話框
我onTouch代碼如下:
public boolean onTouchEvent(MotionEvent event) {
x = event.getX();
y = event.getY();
System.out.println(x);
System.out.println(y);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
AlertDialog.Builder builder = new Builder(getContext());
final EditText text = new EditText(getContext());
builder.setTitle("Change Name")
.setMessage("New Name").setView(text);
builder.setPositiveButton("Change",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface di, int i) {
name = text.getText().toString();
}
});
builder.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface di, int i) {
}
});
builder.create().show();
}
break;
case MotionEvent.ACTION_UP:
sX = event.getX();
sY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
fX = event.getX();
fY = event.getY();
break;
}// switch
return true;
}// ontouch
它的工作!謝謝! – user3306996
我很高興我可以幫助:) – Laura