更改按钮的背景,最后使其消失

时间:2012-09-26 17:57:43

标签: android

  
    

在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;
}

0 个答案:

没有答案