The more general extension of ViewPager would bet to create a "SetPagingEnabled" method so that we can enable and disable paging on the fly. To enable / disable the swiping, just overide two methods: "onTouchEvent" and "onInterceptTouchEvent". Both will return "false" if the paging was disabled.

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

Then select this instead of the builtin viewpager in XML

<mypackage.CustomViewPager
android:id="@+id/myViewPager"
android:layout_height="match_parent"
android:layout_width="match_parent" />

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

http://stackoverflow.com/questions/9650265/how-do-disable-paging-by-swiping-with-finger-in-viewpager-but-still-be-able-to-s

How do disable paging by swiping with finger in ViewPager but still be able to swipe programmatically?的更多相关文章

  1. Process Kill Technology && Process Protection Against In Linux

    目录 . 引言 . Kill Process By Kill Command && SIGNAL . Kill Process By Resource Limits . Kill Pr ...

  2. Early 80386 CPUs

    Assembling a detailed and accurate history of the 80386, including a complete listing of all the &qu ...

  3. asp.net core 排序过滤分页组件:sieve(1)

    使用asp.net core开发时避免不了要用一个合适的分页组件来让前端获取分页数据.github上面有一个开源的分页组件在这方面很适合我的使用,于是我把他的文档翻译一下,随后会分析它里面的源码.这是 ...

  4. How To Make A Swipeable Table View Cell With Actions – Without Going Nuts With Scroll Views

    How To Make A Swipeable Table View Cell With Actions – Without Going Nuts With Scroll Views  Ellen S ...

  5. 放弃WebView,使用Crosswalk做富文本编辑器

    版权声明: 欢迎转载,但请保留文章原始出处 作者:GavinCT 出处:http://www.cnblogs.com/ct2011/p/4100132.html 为什么放弃WebView Androi ...

  6. Android设计和开发系列第二篇:Navigation Drawer(Design)

    Navigation Drawer Creating a Navigation Drawer The navigation drawer is a panel that transitions in ...

  7. OPENVPN2.3配置文档官方说明

    openvpn Section: Maintenance Commands (8)Index NAME openvpn - secure IP tunnel daemon. SYNOPSIS open ...

  8. MySQL之mysql命令使用详解

    MySQL Name mysql - the MySQL command-line tool Synopsis mysql [options] db_name Description mysql is ...

  9. android抽屉导航的设计准则

    我阅读了google官方的关于抽屉导航的设计准则,这可以给我带来什么帮助?最起码,我可以知道,抽屉导航适用在什么场景中,使用它时要注意什么事项.App的设计是有规则可以依据的,比如,使用抽屉导航时,是 ...

随机推荐

  1. 【原则】常用windows开发 客户端工具 收集

    1.  Navicat Premium 推荐: mysql客户端, postgreSQL 客户端, Sqlite客户端 2.  robomongo 推荐:mongoDB客户端

  2. 重磅消息:JavaFX官方文档翻译完毕

    经过XMan团队业余时间半年的努力,终于将JavaFX官方文档全部翻译完毕,内容已经全部在http://www.javafxchina.net中发表. 中文文档具体目录如下: 第一篇 开始学习Java ...

  3. 适配i5,要加入i5的启动页才行,否则运行的效果还是i4

    适配i5,要加入i5的启动页才行,否则运行的效果还是i4

  4. JAXL发送房间消息

    使用composer形式安装的JAXL <?php require_once "vendor/autoload.php"; $client = new JAXL(array( ...

  5. 一步步搭建自己的轻量级MVCphp框架-(四)一个国产轻量级框架Amysql源码分析(3) 总进程对象

    AmysqlProcess类,框架的总进程对象 ./Amysql/Amysql.php 下面还是和以前一样,先上代码~ class AmysqlProcess { public $AmysqlCont ...

  6. 【转】C# 中访问修饰符

    用通过代码:  类内部 using System;class Mod{    void defaultMethod()    {        Console.WriteLine("this ...

  7. Oracle学习笔记1:win7 x64下安装Oracle10g

    oracle 10g在win7x64下的安装: 第一次直接双击setup,出错了…… 可能是兼容性的问题,所以试着 右击setup-->属性-->兼容性-->勾上"以兼容模 ...

  8. Android使用JNI(从java调用本地函数)

    当编写一个混合有本地C代码和Java的应用程序时,需要使用Java本地接口(JNI)作为连接桥梁.JNI作为一个软件层和API,允许使用本地代码调用Java对象的方法,同时也允许在Java方法中调用本 ...

  9. ORACLE 数据库概述以及Oracel数据库的安装、卸载、使用

    一:Orcale简介 1.发展史 1978年,Orcale诞生 1982年,Orcale3推出了,它是第一个能够运行在大型机和小型机上的关系型数据库 1997年,Orcale公司推出了基于java语言 ...

  10. ArrayList与List对象用法与区别

    比如: 代码如下 复制代码 string[] s=new string[3];//赋值s[0]="a";s[1]="b";s[2]="c"; ...