Reputation: 69
I am trying to add a custom ViewPager
for enabling/disabling swipe feature but i have been getting errors. I have implemented custom_viewpager in a separate class and extended the ViewPager
.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center_vertical" >
<com.example.sumit.myapplication.custom_viewpager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pager_threee"
xmlns:android="http://schemas.android.com/apk/res/android" />
</LinearLayout>
The related JAVA code is:
import android.support.v4.view.ViewPager;
ViewPager vp;
private static double latitude = 0.0;
private static double longitude = 0.0;
private static String Country = "";
private static String Locality = "";
private static String AreaCode = "";
private static String My_Id = "0";
List<Fragment> fragments = new ArrayList<Fragment>();
Fragment frag_public_list;
Fragment frag_users_list;
Fragment frag_profile;
Fragment frag_photos;
adapter _adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main__users__page);
frag_users_list = new users_list();
Bundle bundle = new Bundle();
bundle.putDouble("lat", latitude);
bundle.putDouble("long", longitude);
bundle.putString("Country", Country);
bundle.putString("Locality", Locality);
bundle.putString("AreaCode", AreaCode);
bundle.putString("My_Id", My_Id);
frag_users_list.setArguments(bundle);
frag_public_list = new public_chat();
fragments.add(frag_public_list);
fragments.add(frag_users_list);
vp = (ViewPager) findViewById(R.id.pager_threee);
The exception I have been getting is:
Java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sumit.myapplication/com.example.sumit.myapplication.Main_Users_Page}: android.view.InflateException: Binary XML file line #7: Error inflating class com.example.sumit.myapplion.custom_viewpager
The custom_viewpager class is:
package com.example.sumit.myapplication;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* Created by Sumit on 7/27/2015.
*/
public class custom_viewpager extends ViewPager {
private boolean enabled;
public custom_viewpager(Context context) {
super(context);
}
@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;
}
}
Upvotes: 0
Views: 40
Reputation: 5146
You'll need to add the following constructors for your custom_viewpager
class to be inflated correctly:
public custom_viewpager(Context context, AttributeSet attrs) {
super(context, attrs);
}
public custom_viewpager(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
Upvotes: 1