1

在 if 循环中,即使将按钮的背景图像设置为 i_1 并使其休眠五秒钟后,按钮的图像也不会显示,而是屏幕等待五秒钟,按钮消失..任何人都可以找出问题所在..

public class MainActivity extends Activity {
Button b1,b2;
int a=0,b=0,ctr=0;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
     b1=(Button)findViewById(R.id.button1);
     b2=(Button)findViewById(R.id.button2);

}
public void onclick(View V){


switch(V.getId())
{
case R.id.button1:
{


    if(a==2)
{   try {
    b1.setBackgroundResource(R.drawable.i_1);
    Thread.sleep(5000);
    b5.setVisibility(V.GONE);
    b1.setVisibility(V.GONE);
} catch (InterruptedException e) {
     //TODO Auto-generated catch block
    e.printStackTrace();
}
ctr=0;b=0;
    }
    else
    {
        ctr++;

        b=a;
        a=1;
        if(ctr>=2)
        {
    b1.setBackgroundResource(R.drawable.cd);//created xml file:named cd
    switch(b)
    {
 //stmts



    }b=0;ctr=0;
        }
    }
            break;
}
4

0 回答 0