2

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 =)

CocoNess
  • 4,213
  • 4
  • 26
  • 43
Sultan Zeybek
  • 33
  • 1
  • 8

3 Answers3

1

place the login layout inside a transparent, full screen layout, and detect touch events on the larger layout.

Steelight
  • 3,347
  • 1
  • 20
  • 17
0

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;
            }
        });
edwin
  • 7,985
  • 10
  • 51
  • 82
Sultan Zeybek
  • 33
  • 1
  • 8
0

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();
    }
Hesam
  • 52,260
  • 74
  • 224
  • 365