Issue
I'm adding a fragment to an activity instead of replacing the current fragment (because this corresponds to the type of behavior I want to have).
My problem is that clicking in a spot on the top fragment (the one that's currently visible), where a view in the non-visible fragment is located, causes an onClick event on the view in the second, non-visible fragment, to fire. Why is this happening and how can I prevent this?
This is the code I use to first add the ListView fragment to the activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
if (savedInstanceState == null) {
listFragment = new ListFragment ();
getSupportFragmentManager().beginTransaction()
.add(R.id.frame_container, listFragment)
.addToBackStack(listFragment .TAG)
.commit();
}
...
}
In this same activity I'm adding the second fragment, on top of the list fragment:
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
...
createItemFragment = new CreateItemFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.frame_container, createItemFragment)
.addToBackStack(createItemFragment.TAG)
.commit();
...
}
Solution
You can just add the following attribute to the XML root layout of the fragment that agoes on top-
android:clickable="true"
This will ensure that touch events will not propagate further than the top layer.
Answered By - C0D3LIC1OU5
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.