如何禁用在android系统视图寻呼机刷卡 [英] How to disable swipes in a view pager in android

查看:134
本文介绍了如何禁用在android系统视图寻呼机刷卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的机器人。我创建其中包括与刷卡标签布局视图寻呼机的应用程序。当我点击按钮,它做了一些计算的看法寻呼机内。虽然它做这个我想在标签之间的切换被禁用。因此,没有页面之间滑动,而它的计算。
计算完成后,我想在开关被再次激活。谁能告诉我如何做到这一点吗?
提前致谢。
我想这一点。请看看吧:

 公共类自动扩展FragmentActivity {
    按键测试;
    私人ViewPager寻呼机;
    @覆盖
        保护无效的onCreate(捆绑savedInstanceState){
            super.onCreate(savedInstanceState);
            的setContentView(R.layout.auto);
                测试=(PaperButton)findViewById(R.id.action_button_tests);
                tests.setOnClickListener(新View.OnClickListener(){                    @覆盖
                    公共无效的onClick(视图v){
                        如果(pager.getCurrentItem()== 0){
                            tests.setTag(1);
                            tests.setText(开始测试);
                        最终诠释状态=(整数)v.getTag();
                        如果(状态== 1){
                            tests.setText(STOP TEST);
                            v.setTag(0);
                            INT I;
                            Login.Communication_Ok = FALSE;
                            对于(I = 0;(I小于5&放大器;&放大器;!Login.Communication_Ok =真);我+ +)
                            Login.Send_Commands_To_Micro_Controller(1);
                            如果(Login.Communication_Ok ==真)
                            {
                                Video_Status = FALSE;
                                Login.Bucket_Status = FALSE;
                                Login.Auto_Mode_Bfr_Fuse = FALSE;
                                对于(I = 0;(I小于5&放大器;&放大器;!Login.Auto_Mode_Bfr_Fuse =真);我+ +)
                                Login.Send_Commands_To_Micro_Controller(3);
                                如果(Login.Auto_Mode_Bfr_Fuse ==真)
                                Toast.makeText(Auto.this,测试开始,Toast.LENGTH_LONG).show();
                                其他
                                {
                                Toast.makeText(Auto.this,Toast.LENGTH_LONG在之前保险丝连接段通信故障).show();
                                tests.setText(开始测试);
                                v.setTag(1);
                                返回;
                                }
                                Test_Completed = FALSE;
                                如果(!Auto_Bucket_Tests_Thread.isAlive())
                                Auto_Bucket_Tests_Thread.start();
                            }                        }
                        其他{
                            tests.setText(开始测试);                            v.setTag(1);
                        }
                        }
                        如果(pager.getCurrentItem()== 1){
                            tests.setTag(1);
                            tests.setText(开始测试);                            最终诠释状态=(整数)v.getTag();
                            如果(状态== 1){
                                tests.setText(STOP TEST);
                                v.setTag(0);
                                INT I;
                                Login.Communication_Ok = FALSE;
                                对于(I = 0;(I小于5&放大器;&放大器;!Login.Communication_Ok =真);我+ +)
                                Login.Send_Commands_To_Micro_Controller(1);
                                如果(Login.Communication_Ok ==真)
                                {
                                    Video_Status = FALSE;
                                    Login.Bucket_Status = FALSE;
                                    Login.Automode_After_connecting_fuse = FALSE;
                                    对于(I = 0;(I小于5&放大器;&放大器;!Login.Automode_After_connecting_fuse =真);我+ +)
                                    Login.Send_Commands_To_Micro_Controller(4);
                                    如果(Login.Automode_After_connecting_fuse ==真){
                                    Toast.makeText(Auto.this,测试开始,Toast.LENGTH_LONG).show();                                    ** / *对于标签之间禁止刷卡* / **
                                    pager.setOnTouchListener(新OnTouchListener(){                                        @覆盖
                                        公共布尔onTouch(视图V,MotionEvent事件){
                                            pager.getCurrentItem();
                                            返回false;
                                        }
                                    });
                                    pager.setEnabled(假);                                    }
                                    其他
                                    {
                                    Toast.makeText(Auto.this,Toast.LENGTH_LONG在保险丝连接后段的通信失败).show();
                                    tests.setText(开始测试);
                                    v.setTag(1);
                                    返回;
                                    }
                                    Test_Completed = FALSE;                                }
                            }
                            其他{
                                tests.setText(开始测试);                                v.setTag(1);
                                }                    }
}}


解决方案

 公共类CustomViewPager扩展ViewPager {启用私人布尔;公共CustomViewPager(上下文的背景下,ATTRS的AttributeSet){
超(背景下,ATTRS);
this.enabled = TRUE;
}@覆盖
公共布尔onTouchEvent(MotionEvent事件){
如果(this.enabled){
    返回super.onTouchEvent(事件);
}返回false;
}@覆盖
公共布尔onInterceptTouchEvent(MotionEvent事件){
如果(this.enabled){
    返回super.onInterceptTouchEvent(事件);
}返回false;
}公共无效setPagingEnabled(布尔启用){
this.enabled =启用;
}}

您只需要调用setPagingEnabled方法,假,用户将无法刷卡进行分页。

I am new to android. I am creating an app which consists of a view pager with a swipe tab layout. When I click the button it does some calculations inside of the view pager. While it's doing this I want the switching between the tabs to be disabled. So no swiping between the pages while it's calculating. After the calculations are completed I want the switching to be enabled again. Can anyone tell me how to do this please? Thanks in advance. I tried this. Please have a look at it:

    public class Auto extends FragmentActivity{
    Button tests;
    private ViewPager pager;
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.auto);
                tests = (PaperButton)findViewById(R.id.action_button_tests);
                tests.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if(pager.getCurrentItem()==0){
                            tests.setTag(1);
                            tests.setText("START TEST");
                        final int status = (Integer)v.getTag();
                        if(status==1){
                            tests.setText("STOP TEST");
                            v.setTag(0);
                            int i;
                            Login.Communication_Ok=false;
                            for( i=0;(i<5 && Login.Communication_Ok!=true);i++)
                            Login.Send_Commands_To_Micro_Controller(1);
                            if(Login.Communication_Ok==true)
                            {
                                Video_Status=false;
                                Login.Bucket_Status = false;
                                Login.Auto_Mode_Bfr_Fuse =false;
                                for( i=0;(i<5 && Login.Auto_Mode_Bfr_Fuse!=true);i++)
                                Login.Send_Commands_To_Micro_Controller(3);
                                if(Login.Auto_Mode_Bfr_Fuse==true)
                                Toast.makeText(Auto.this, "Test started", Toast.LENGTH_LONG).show();
                                else
                                {
                                Toast.makeText(Auto.this, "Communication Failure in Before Fuse connection Segment", Toast.LENGTH_LONG).show();
                                tests.setText("START TEST");
                                v.setTag(1);
                                return;
                                }
                                Test_Completed=false;
                                if(!Auto_Bucket_Tests_Thread.isAlive())
                                Auto_Bucket_Tests_Thread.start();


                            }

                        }
                        else{
                            tests.setText("START TEST");

                            v.setTag(1);
                        }
                        }


                        if(pager.getCurrentItem()==1){
                            tests.setTag(1);
                            tests.setText("START TEST");

                            final int status = (Integer)v.getTag();
                            if(status==1){
                                tests.setText("STOP TEST");
                                v.setTag(0);
                                int i;
                                Login.Communication_Ok=false;
                                for( i=0;(i<5 && Login.Communication_Ok!=true);i++)
                                Login.Send_Commands_To_Micro_Controller(1);
                                if(Login.Communication_Ok==true)
                                {
                                    Video_Status=false;
                                    Login.Bucket_Status = false;
                                    Login.Automode_After_connecting_fuse =false;
                                    for( i=0;(i<5 && Login.Automode_After_connecting_fuse!=true);i++)
                                    Login.Send_Commands_To_Micro_Controller(4);
                                    if(Login.Automode_After_connecting_fuse==true){
                                    Toast.makeText(Auto.this, "Test started", Toast.LENGTH_LONG).show();



                                    **/*For Disabling swipe between tabs*/**
                                    pager.setOnTouchListener(new OnTouchListener() {

                                        @Override
                                        public boolean onTouch(View v, MotionEvent event) {
                                            pager.getCurrentItem();
                                            return false;
                                        }
                                    });
                                    pager.setEnabled(false);

                                    }
                                    else
                                    {
                                    Toast.makeText(Auto.this, "Communication Failure in After Fuse connection Segment", Toast.LENGTH_LONG).show();
                                    tests.setText("START TEST");
                                    v.setTag(1);
                                    return;
                                    }
                                    Test_Completed=false;

                                }


                            }
                            else{
                                tests.setText("START TEST");

                                v.setTag(1);
                                }

                    }
}   }

解决方案

public class CustomViewPager extends ViewPager {

private boolean enabled;

public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.enabled = true;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.enabled) {
    return super.onTouchEvent(event);
}

return false;
}

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.enabled) {
    return super.onInterceptTouchEvent(event);
}

return false;
}

public void setPagingEnabled(boolean enabled) {
this.enabled = enabled;
} }

You just need to call the "setPagingEnabled" method with "false" and users won't be able to swipe to paginate.

这篇关于如何禁用在android系统视图寻呼机刷卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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