Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Try to inflate a custom viewpage android

I have extend Viewpage class but the problem is I always get java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pindak.sarito/com.pindak.sarito.ui.ws.MagazineReaderActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class com.pindak.sarito.util.HackyViewPager. When trying to inflate it.

this is my layout

<?xml version="1.0" encoding="utf-8"?>
<com.pindak.sarito.util.HackyViewPager xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/magazinepager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

this is the some of the code of my onCreate in activity

HackyViewPager pager = (HackyViewPager) findViewById(R.id.magazinepager);

and In com.pindak.sarito.util I have HackyViewPager.java

package com.pindak.sarito.util;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;

public class HackyViewPager extends ViewPager {

    public HackyViewPager(Context context) {
        super(context);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return false;
        }
    }

}

Any Ideas Why I am getting this error?

like image 860
Chris Ian Avatar asked Feb 27 '13 02:02

Chris Ian


People also ask

How to set ViewPager in Android?

To use ViewPager and tabs, you need to add a dependency on ViewPager and on Material Components to your project. To insert child views that represent each page, you need to hook this layout to a PagerAdapter .

How to create ViewPager adapter in Android?

Steps for implementing viewpager: Adding the ViewPager widget to the XML layout (usually the main_layout). Creating an Adapter by extending the FragmentPagerAdapter or FragmentStatePagerAdapter class.

What is ViewPager Android?

ViewPager in Android allows the user to flip left and right through pages of data. In our android ViewPager application we'll implement a ViewPager that swipes through three views with different images and texts.


1 Answers

Have you tried adding constructors that match both super constructiors?

public HackyViewPager(Context context) {
    super(context);
}

public HackyViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
}
like image 154
alex Avatar answered Sep 18 '22 06:09

alex