如何prevent活动从$ P $加载两次pssing按钮 [英] How to prevent the activity from loading twice on pressing the button

查看:162
本文介绍了如何prevent活动从$ P $加载两次pssing按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出是prevent活动从加载两次,如果我preSS两次按钮。

What I am trying to figure out is to prevent the activity from loading twice if I press the button twice.

我有它加载上点击一个按钮的一个活动,说

I have an activity which loads on click of a button, say

 myButton.setOnClickListener(new View.OnClickListener() {
      public void onClick(View view) {
       //Load another activity
    }
});

现在,因为要加载的活动有一些事情与Web服务等操作,这需要一点时间来加载。当然,我有这样的加载视图。 但在此之前,如果我preSS的按钮两次,我可以看到该活动被加载两次。

Now because the activity to be loaded has some thing to do with the webservice and other operations, it takes a little time for it to load. Of course, I have a loading view for this. But before that, if I press the button twice, I can see the activity being loaded twice.

做任何一个知道如何prevent呢?

Do any one know how to prevent this?

推荐答案

在该按钮的事件监听器,禁用按钮,显示出另一项活动。

In the button's event listener, disable the button and show another activity.

    Button b = (Button) view;
    b.setEnabled(false);

    Intent i = new Intent(this, AnotherActitivty.class);
    startActivity(i);

覆盖 onResume()来重新启用按钮。

@Override
    protected void onResume() {
        super.onResume();

        Button button1 = (Button) findViewById(R.id.button1);
        button1.setEnabled(true);
    }

这篇关于如何prevent活动从$ P $加载两次pssing按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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