Reputation: 33
Hi everybody =) i am a new android developer and i need a help about dismissing fragment.
My application have an login fragment and when the user touch the outside of it i want to hide login fragment. How can i make this? OnTouchEvent() method may be useful or not?
Please say something. Thanks =)
Upvotes: 2
Views: 4764
Reputation: 33
Hi again =) i solve this problem using OnTouchListener on my Homepage activity.I have an gridviews background in my homepage layout and if the user doesn't login, onTouch()
method runs.When the login fragment is visible and the user touch outside of it my hideLoginFragment() method calling for dismissing the fragment..
gridView = (ShelvesView) findViewById(R.id.grid_shelves);
gridView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (application.getDbManager().getUser().key.equals("-1")){
hideLoginFragment();
loginButton.setVisibility(View.VISIBLE);
exitButton.setVisibility(View.INVISIBLE);}
return false;
}
});
Upvotes: 0
Reputation: 53600
I think better way is removing fragment in order to release memory resources.
My solution is having having this method in fragment:
private void closeFragment() {
getActivity().getSupportFragmentManager().beginTransaction().remove(YOUR_FRAGMENT.this).commit();
}
Upvotes: 0
Reputation: 3357
place the login layout inside a transparent, full screen layout, and detect touch events on the larger layout.
Upvotes: 1