Android custom ViewPager is not allowing me to click on the View components -
i using fragmentstatepageradapter custom viewpager. using standard viewpager , able swipe fragments correctly , interact edittexts/buttons , other components on different views, had create custom viewpager when restricting swipe direction. once used custom viewpager, displays correctly etc unable click of edittexts/buttons etc.
can see problem this? assuming signuppager not overriding method or incorrectly handling motionevent.... none of attempts have worked.
signuppager.java:
import android.content.context; import android.support.v4.view.viewpager; import android.util.attributeset; import android.view.motionevent; public class signuppager extends viewpager{ public signuppager(context context){ super(context); } public signuppager(context context, attributeset attrs) { super(context, attrs); } private float initialxvalue; public swipedirection direction = swipedirection.all; @override public boolean ontouchevent(motionevent event) { if (this.isswipeallowed(event)) { return super.ontouchevent(event); } return false; } @override public boolean onintercepttouchevent(motionevent event) { if (this.isswipeallowed(event)) { return super.ontouchevent(event); } return false; } private boolean isswipeallowed(motionevent event) { if(this.direction == swipedirection.all) return true; if(direction == swipedirection.none )//disable swipe return false; if(event.getaction()==motionevent.action_down) { initialxvalue = event.getx(); return true; } if(event.getaction()==motionevent.action_move) { try { float diffx = event.getx() - initialxvalue; if (diffx > 0 && direction == swipedirection.right ) { // swipe left right detected return false; } else if (diffx < 0 && direction == swipedirection.left ) { // swipe right left detected return false; } } catch (exception exception) { exception.printstacktrace(); } } return true; } public enum swipedirection { all, left, right, none ; } }
in mainactivity.java connect signuppager fragmentstatepageradapter (note have copied critical lines of code part):
public signupadapter signupadapter; public static signuppager pager; signupadapter = new signupadapter(getsupportfragmentmanager()); pager = (signuppager) findviewbyid(r.id.signupviewpager); pager.setadapter(signupadapter) public static class signupadapter extends fragmentstatepageradapter{ .......... }
sign_up.xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <signup.signuppager android:id="@+id/signupviewpager" android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="1" /> </linearlayout>
fragment_view.xml (this xml view of unable click components) :
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/signuplayout" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/holo_orange_dark" tools:context="com.example.tabbyreyez.helloworld.signupsecondarycontroller"> <textview android:id="@+id/signupdatatitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/signupdata" android:layout_margintop="30dp" android:layout_marginleft="27dp" android:textsize="35dp"/> <textview android:id="@+id/firstnamelabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="first name:" android:layout_below="@+id/signupdatatitle" android:layout_margintop="30dp" android:layout_marginleft="10dp" android:textsize="17dp"/> <edittext android:id="@+id/firstname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputtype="textpersonname" android:hint="e.g. tabraiz" android:layout_below="@+id/signupdatatitle" android:layout_margintop="18dp" android:layout_marginleft="130dp" android:ems="9"/> <textview android:id="@+id/lastnamelabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="last name:" android:layout_below="@+id/firstnamelabel" android:layout_margintop="23dp" android:layout_marginleft="10dp" android:textsize="17dp" /> <edittext android:id="@+id/lastname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputtype="textpersonname" android:hint="e.g. malik" android:layout_below="@+id/firstname" android:layout_marginleft="130dp" android:ems="9" /> <button android:id="@+id/signupbutton" android:layout_width="100dp" android:layout_height="wrap_content" android:text="sign up" android:layout_below="@+id/passwd" android:layout_centerhorizontal="true" /> </relativelayout>
try following in mainactivity should extend fragmentactivity.
private pageradapter mpageradapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); super.setcontentview(r.layout.sign_up); //initialize pager this.initialisepaging(); } /** * initialize fragments paged */ private void initialisepaging() { list<fragment> fragments = new vector<fragment>(); fragments.add(fragment.instantiate(this, myfragment1.class.getname())); fragments.add(fragment.instantiate(this, myfragment2.class.getname())); fragments.add(fragment.instantiate(this, myfragment3.class.getname())); this.mypageradapter = new pageradapter(super.getsupportfragmentmanager(), fragments); viewpager pager = (viewpager) super.findviewbyid(r.id.signupviewpager); pager.setadapter(this.mpageradapter); }
i see no reason why should create custom signupadapter extends fragmentstatepageradapter. instead, try using pageradapter.
Comments
Post a Comment