4

so i have 3 fragments, in each fragment there is floating action button when clicked it will go to an another activity.

what i did is make the floating action in the mainActivity to public so i can use it to the fragments. my code

public FloatingActionButton fab;


fab = (FloatingActionButton) findViewById (R. id. fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

code in fragment:

@Override
    public void setUserVisibleHint(boolean visible)
    {
        super.setUserVisibleHint(visible);
        if (visible && isResumed())
        {
            onResume();
        }
    }

    public void onResume()
    {
        super.onResume();
        if (!getUserVisibleHint())
        {
            return;
        }

        MainEventActivity mainActivity = (MainEventActivity)getActivity();
        mainActivity.fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(this, MapActivity.class);
                startActivity(intent);
            }
        });
    }

i dont know what to do next, i tried to put the floating action button in the MainEvent.xml it doesnt show up, but when i put it in the fragment.xml it shows but cant click. can you guys help me?

Btw i did this because i dont know how to put googlemaps in a fragment so i made a new activity for googlemaps.

Abhishek
  • 1,654
  • 2
  • 18
  • 31
ErlAl
  • 439
  • 1
  • 7
  • 13

0 Answers0