Search code examples
androidandroid-fragmentsnavigation-drawerdrawerlayout

Android Drawer Layout with Fragments


I am using the preset Android Drawer layout. Each selection in the drawer launches a different fragment into the main activity area. My app is used to connect to a SQL server, so I have Username/Password EditTexts and a login button sitting on the app_bar_main for that. How can I make it so that when I hit the login button, it can call a method that is in my fragment?


Solution

  • In your fragment

    EditText userName = getActivity().findViewById(R.id.username_id); // id given in your activity layout
    EditText password = getActivity().findViewById(R.id.password_id);
    Button login = getActivity().findViewById(R.id.button_id);
    userName.getText();
    password.getText();
    login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
    
            }
        });