public class Main2Activity extends AppCompatActivity {
int square5 = 0;
int flag = 1;
int userclick5 = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
//here i set some click listeners. one example is as follows:
ImageButton image_button1 = (ImageButton) findViewById(R.id.image_button1);
image_button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
goToIB();
}
});
}
//click listener call this function. This function set the color of image button as green.
//Then it calls the function goTofirst3cpu()
private int goToIB() {
ImageButton imageButton5 = (ImageButton) findViewById(R.id.image_button5);
if (imageButton5.isPressed() & square5 == 0) {
{
imageButton5.setImageResource(R.color.green_color);
flag = flag + 1;
square5 = square5 + 1;
userclick5 = userclick5 + 1;
goTofirst3cpu();
return square5;
}
}
return 0;
}
//This function shows red color in image button
private void goTofirst3cpu() {
ImageButton imageButton5 = (ImageButton) findViewById(R.id.image_button5);
if (square5 == 0) {
//HERE IS WHAT I NEED TO DO SOMETHING
//when i do something, there will be a gap of 5 seconds
//before changing imagebutton's color from green to red.
//????????? WHAT I WILL DO HERE. ??????
imageButton5.setImageResource(R.color.red_color);
square5 = square5 + 1;
}
}
}
我用吐司和所有的东西。还有系统时钟。但这些东西对我不起作用。在将图像按钮的颜色更改为红色之前,我需要休息 5 秒。我是编程新手。所以用简单的语言解释。提前致谢.....