I have some pages which is loading into viewpager. I want to determine if there any way to find out if user touch the view(inside page) when the page is visible? My view pager page view is something like this Basic1.java and initshape() method as describe . Please let me know any more information is required.
implement following code in a page(fragment) you want to detect touch event.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout containing a title and body text.
ViewGroup rootView = (ViewGroup) inflater
.inflate(R.layout.fragment_slide, container, false);
LinearLayout layout = (LinearLayout)rootView.findViewById(R.id.layout)// get your root layout
layout.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.v(null, "TOUCH EVENT"); // handle your fragment touch here
return false;
}
});
return rootView;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.