【发布时间】:2016-04-03 12:58:47
【问题描述】:
public class MainActivity extends Activity {
ImageView img;
MediaPlayer failure;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bButton= (Button)findViewById(R.id.blueBtn);
img = (ImageView)findViewById(R.id.image);
img.setVisibility(View.VISIBLE);
failure= MediaPlayer.create(this,R.raw.failure_sound);
bButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
img.setVisibility(View.VISIBLE);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
failure.start();
}
});
}
这就是我的代码。 我只是想让它在我按下按钮时显示图像 然后等待 1000 毫秒,然后发出声音。 但是(!)不幸的是,当我按下该按钮时:该过程等待 1000 毫秒,然后发出声音并显示 img。
请帮忙!!!
【问题讨论】:
-
使用
Handler而不是Thread.sleep -
如果我想显示图像,然后延迟整个程序,然后继续并发出声音怎么办。 (我当然会问,因为我有很多问题......)
-
可以请人在这里帮助我。我想要在不冻结我的 UI 的情况下产生与睡眠相同效果的东西。亨德勒不会让我的程序停止。我想在 for 循环中间停止程序,显示图片,然后停止一切(循环)。但处理程序不这样做。最好的毕业生
标签: android eclipse image button imageview