I have an Activity that loads 2 fragments in its XML file, these two fragments have a custom view.
This view is a joy stick so it has an onTouch method, however I want to get the X and Y values from the view to use in the Activity.
I’ve tried getting the ActivityContext in the fragment and passing that into the view but that doesn’t give me the instance.
I’ve also tried getting access to the view from the Activity without any luck.
Can anyone recommend a method for passing this data?
There is a nice training article about fragment to fragment communication via Activity.
You basically should have the activity implement a custom callback interface. Best way of getting hold of the activity is in fragment’s onAttach(Activity activity) method.
From what I understand, you want to add onTouchListener to your view, which in turn will call the callback you implemented with the values you require.