如何在android中的按钮上使用可见和不可见 [英] how to use visible and invisible for a button in android

查看:41
本文介绍了如何在android中的按钮上使用可见和不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让一个按钮不可见,当我单击另一个按钮时,不可见按钮将变为可见,然后对可见按钮执行 onClick() 操作.

I want to make a button invisible, when i click another button then the invisible button will become visible and then perform onClick() actions on the visible button.

我可以在可见按钮上使用哪些 onClick() 操作.我使用了如下所示的这种方法:

What onClick() actions I can use on the visible button. I used this method shown below:

   donebutton = (Button) findViewById(R.id.done);
    donebutton.setOnClickListener(this);
    donebutton.setVisibility(View.INVISIBLE);

    @Override
     public void onClick(View v) {
    // TODO Auto-generated method stub
         if(v.equals(remove))
           {
             donebutton.setVisibility(View.VISIBLE);
           }
        if(v.equals(donebutton))
            {
                Intent i=new Intent(One.this,Second.class);
                startActivity(i);
                finish();
                donebutton.setVisibility(View.INVISIBLE);
            }

      }

在上述方法中,不可见和可见属性都可以工作,但 onClick() 操作不工作.所以请告诉我上述问题的答案,或者告诉我是否有任何其他方法可以让按钮上的可见和不可见以及该按钮上的 onclick 操作.

In the above method the invisible and visible propertyes are working but onClick() action is not working. so please tell me an answer for the above problem or tell me if there is any other method for visible and invisible on button and onclick action on that button.

我也用过这个方法:

       done.setClickable(true);
       done.setOnClickListener(new OnClickListener(){
         public void onClick(View v) {
            Intent i=new Intent(One.this,Second.class);
            startActivity(i);
            finish();
         }
     });

推荐答案

不要使用 -

donebutton.setVisibility(4);

改为使用静态常量:

donebutton.setVisibility(View.VISIBLE);

具体是什么意思

done.setVisibility(0);

不应该是

donebutton.setVisibility(View.GONE);

这篇关于如何在android中的按钮上使用可见和不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆