Как обращаться к объектам вне фрагмента? - PullRequest
0 голосов
/ 10 февраля 2020

Я пытаюсь заменить содержимое представления изображения из несвязанного Fragment. В частности, представление изображения, которое я хочу отредактировать, находится в ящике меню.

Как в этом случае правильно адресовать ImageView?

public class MyFragment extends Fragment {

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

        root = inflater.inflate(R.layout.myFragment, container, false);

        // imageView in nav_header_main.xml

        // Usually all objects in fragment are address through root.any_object_id
        // profileImage = root.findViewById(R.id.profileImage);

        // But how to address the ImageView properly which is in nav_header_main.xml?
        //profileImage = root.findViewById(R.id.profileImage); // No luck
        profileImage = getActivity().findViewById(R.id.profileImage); // No luck

        profileImage.setImageURI(someResultUri);

        return root;
    }

}
...