How to disable ViewPager scrolling with android-support-v4.jar in android

I am creating an Android application with a target value of 2.2. I still want to use the ViewPager provided in android.support-v4.jar.i, I need to disable the Viewpager view on the click.i button, use the following code to disable it. but its not working.

public class ServiesDeail extends FragmentActivity{ ServiesTitleFragmentAdapter mAdapter; ViewPager mPager; int position = 0 ; @SuppressWarnings({ "rawtypes", "unchecked" }) @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mastermenu); LinearLayout lnrparent = (LinearLayout) findViewById(R.id.LL_001); LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.menu_deatil, null); lnrparent.addView(view); mAdapter = new ServiesTitleFragmentAdapter(getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.pagerone); mPager.setAdapter(mAdapter); TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.indicatorone); indicator.setViewPager(mPager,position); Menu_Button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPager.setClickable(false); } }); } } 

If you have any ideas, anyone .. please give me an answer .. I'm waiting for your answer

+6
source share
1 answer

You will need to expand the presentation player and create for you a custom presentation pager that can be used in xml instead of the presentation pager that you get from the support library and change some properties, see the code below, it worked for me. Use customviewpager in your code and the check will be disabled.

 public class CustomViewPager extends ViewPager{ public CustomViewPager(Context context){ super(context); } public CustomViewPager(Context context, AttributeSet attrs) { super(context, attrs); } @Override public boolean onInterceptTouchEvent(MotionEvent ev){ return false; } @Override public boolean onTouchEvent(MotionEvent ev){ return false; } } 
+23
source

Source: https://habr.com/ru/post/920558/


All Articles