Reputation: 63
Basically, I want to open a fragment
from Activity
. Everything worked fine (activity button opens the fragment and the fragment shows), until I miss-clicked outside the fragment's
layout where one of the Activity
button is located and it did its onClick
method. That's why I wondered why is my Activity
still active.
this is how I open the fragment
from Activity
I tried using .add
instead of .replace
still the same.
@OnClick(R.id.login_register_lbl)
public void registerAction(View view) {
// TODO register transition...
FragmentManager fragmentManager = (LoginActivity.this.getFragmentManager());
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
RegisterFragment fragment = new RegisterFragment();
fragmentTransaction.replace(R.id.fragment_register_holder, fragment);
fragmentTransaction.commit();
}
Upvotes: 1
Views: 1562
Reputation: 532
In fragment layout in root element set "background" , "clickable=true" & Focusable="true".
Upvotes: 3
Reputation: 409
In my opinion you can achieve this functionality by 2 ways:
Open a dialog fragment in full screen mode to avoid accidentally clicks on activities views.
If you wanted to show both fragment's and activity's views at the same time then, on click of your activity's button which opens the fragment, disable it by yourbutton.setenabled(false);
and when you wanted to close the fragment enable that button again.
Upvotes: 0