下面的代码是为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);
}
看到我的回答你输入错误处理程序 –