Android viewflow validation
Currently I have a few forms using this horizontal sliding view.
https://github.com/pakerfeldt/android-viewflow
Is their a way to prevent the user from sliding to the开发者_Python百科 next screen when the form is filled in incorrectly? e.g. disable the horizontal scroll.
Yes, change this portion of your copy of the ViewFlow
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
....
case MotionEvent.ACTION_MOVE:
//Add an if / else here that validates your input.
//If it is incorrect don't let the rest of the code that is here do the scrolling.
I had the same problem, just added a Boolean variable and a setter and getter:
...
public class ViewFlow extends AdapterView<Adapter> {
private Boolean flagAllowScroll = false;
//the rest of the code
...
public Boolean getFlagAllowScroll() {
return flagAllowScroll;
}
public void setFlagAllowScroll(Boolean flagAllowScroll) {
this.flagAllowScroll = flagAllowScroll;
}
And the put it on the onTouchEvent function
...
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (!getFlagAllowScroll())
return false;
//the rest of the code
...
And other in the onInterceptTouchEvent function
...
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if (!getFlagAllowScroll())
return false;
//the rest of the code
...
And change it of this way:
...
//Allows changes
viewFlow.setFlagAllowScroll(true);
...
//Doesn't Allows changes
viewFlow.setFlagAllowScroll(false);
...
I hope this works for you =)
精彩评论