Java tutorial
/* * Copyright (c) 2016. by Hoang Hiep (hoanghiep8899@gmail.com) * This file CustomViewPager.java is part of File Manager * Create at 3/6/16 2:19 PM * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.filemanager.free.ui.views; import android.content.Context; import android.support.v4.view.ViewPager; import android.util.AttributeSet; import android.view.MotionEvent; /** * Created by Arpit on 16-01-2015. */ 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) { try { if (this.enabled) { return super.onInterceptTouchEvent(event); } } catch (IllegalArgumentException ex) { ex.printStackTrace(); } return false; } public void setPagingEnabled(boolean enabled) { this.enabled = enabled; } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); enabled = true; } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); enabled = false; } }