下面的代碼是爲ImageButton在每次點擊時更改其圖像,我創建了一個循環來改變它的位置,但它改變得非常快。所以我需要一個延遲功能,我試過this solution,但沒有爲我工作。如何爲setOnClickListener設置延遲?
它說: 「處理程序是抽象的,不能被實例化」
代碼:
public void ShapeSelectingInGame() {
ShapeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShapeButton = (ImageButton) v;
selectShape = rand.nextInt(4);
ShapeSaying = rand.nextInt(8);
ColorOfShape = rand.nextInt(10);
shapeID = "shape_" + selectShape + ShapeSaying + ColorOfShape;
resID = getResources().getIdentifier(shapeID, "drawable", "com.example.asgames.hitit");
ShapeButton.setImageResource(resID);
HitTypeString.setVisibility (View.INVISIBLE);
}
});
for (int i=10; i<10000;i+=100)
{
ShapeButton.setX(i);
}
ShapeButton.setVisibility(View.VISIBLE);
}
看到我的回答你輸入錯誤處理程序 –