A
A
arlanchik52018-02-27 22:57:45
Android
arlanchik5, 2018-02-27 22:57:45

How to solve problem with BottomNavigationView?

Hello everyone, I have this problem: Error:(66, 21) error: cannot find symbol method getSupportFragmentManager().
Here is the code:

public class HomeFragment extends Fragment {
    ImageView imageView10,imageView11,imageView12,imageView13,imageView20,imageView21;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.homefragment, container, false);

        BottomNavigationView bottomNav = rootView.findViewById(R.id.bottom_navigation2);
        bottomNav.setOnNavigationItemSelectedListener(navListener2);

        imageView10 = (ImageView) rootView.findViewById(R.id.imageView10);
        imageView11 = (ImageView) rootView.findViewById(R.id.imageView11);
        imageView12 = (ImageView) rootView.findViewById(R.id.imageView12);
        imageView13 = (ImageView) rootView.findViewById(R.id.imageView13);
        imageView20 = (ImageView) rootView.findViewById(R.id.imageView20);
        imageView21 = (ImageView) rootView.findViewById(R.id.imageView21);

        Picasso.with(getContext()).load("http://risovach.ru/upload/2018/02/mem/tak-blet_170171113_orig_.jpg").into(imageView10);
        Picasso.with(getContext()).load("https://cs7.pikabu.ru/post_img/2017/10/19/9/1508424440193128399.jpg").into(imageView11);
        Picasso.with(getContext()).load("http://topmemas.top/img/img/1513686603.jpg").into(imageView12);
        Picasso.with(getContext()).load("http://topmemas.top/img/img/1513686603.jpg").into(imageView13);
        Picasso.with(getContext()).load("http://img0.reactor.cc/pics/post/политика-песочница-политоты-Путин-4232258.jpeg").into(imageView20);
        Picasso.with(getContext()).load("http://risovach.ru/upload/2018/02/mem/otchayannyy-agutin_170091058_orig_.jpg").into(imageView21);
        return rootView;
    }
    private BottomNavigationView.OnNavigationItemSelectedListener navListener2 =
            new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    Fragment selectedFragment = null;

                    switch (item.getItemId()) {
                        case R.id.navigation_mems:
                            selectedFragment = new HomeFragment();
                            break;
                        case R.id.navigation_friends:
                            selectedFragment = new RecyclerFragment();
                            break;
                    }

                    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container2,
                            selectedFragment).commit();
                    return true;
                }
            };

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2018-02-28
@arlanchik5

getActivity().getSupportFragmentManager(). In general, such things need to be encapsulated in a separate class (Router).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question