I am creating an interface where I need to process touch events special By the way I would be able to enable them in a limited area in only one piece. To better understand this problem, to respect the standards and to target my application, I planned the navigation drawer, which considers the presence of many pieces (instead of activities) touch events With an activity very easy to apply, on the other hand I have read on the Internet that can become a problem with pieces .
My application, at the architecture level, is as follows: - Main activity Java - Navigation Drawer Java - testfragment.java (now for a single piece, waiting to solve the problem)
I have not found any solution or tutorial which tells how to do well (Or how to solve the problem), then I ask you, to simplify the problem " one piece (in this case getpressure (to enable touch events)) ". Below are some code that can help solve the problem:
Testfragment
increases the public square testfragment fragment { Private static final string ARG_SECTION_NUMBER = "section_number"; Public Static TestFragment newInstance (int sectionNumber) {TestFragment fragment = new TestFragment (); Bundle args = new bundle (); Args.putInt (ARG_SECTION_NUMBER, section number); Fragment.setArguments (args); Return piece; } Public Trial Fragment () {} @ Override Public View Crate View (Layout Inflator Inflator, View Group Container, Bundle Saved InstantState) {return inflater.inflate (R. Late Fragment_Stest, container, falls); } @ Override Crate on Public Zero (Bundle Saved Instantstate) {Super.Nought (Saved Instantstate); } @ Override Public Boolean on touch event {// Here I want to return the press value (0 to 1)}}
How do I add the listener to the whole piece? And in the case of a special area? Finally, how can I return the value of the pressure on the screen?
Thank you very much for the advice! :)
I'm not sure that I understand your problem, but I will try to answer it . So to get touch events on the piece, I will do this:
- In your Creteview:
View View = inflater.inflate (R.Late Fragment_Test, Container, false); View.setOnTouchListener (see new OnTouchListener) {Public Boolean On-Touch (see V, Motion Event Event) {if (event.getAction () == MotionEvent.ACTION_MOVE) {// do something} back true;}}) ; // Return the rest of your code here;
And you can check different motion accents in touch, for example:
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_UP, ... < / Code>
Comments
Post a Comment