마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

프래그먼트 사용, 체크박스 사용시 전달이 안될때.

0 추천
프래그먼트가 지금 현재 3개가 있습니다.

Main화면을 보여주는 MainFragment

Image를 보여주는 Image프래그먼트

그래고 체크박스를 담고있는 CheckFragment가 있는데,

 

체크박스를 선택하여 이미지를 보여주고 안보여주고를 하려는데

이게 체크박스를 선언하거나 할때마다 자꾸 응답없음 종료가 나오는데

어떻게 해야하나요 ㅠ
익명사용자 님이 2017년 6월 13일 질문

1개의 답변

0 추천
사용한 코드를 보여주세요

이렇게 올리시면 알 수가 없어요

 

아니면 좀 더 자세한 설명이나..
익명사용자 님이 2017년 6월 13일 답변
public class MainFragment extends Fragment {
    
    ImageView Image1;
    ImageView Image2;




    View rootView;


    private OnFragmentInteractionListener mListener;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }


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

        rootView = inflater.inflate(R.layout.fragment_main, container, false);
        pref = getActivity().getSharedPreferences(getResources().getString(R.string.app_name), MODE_PRIVATE);



        Image1 = (ImageView)rootView.findViewById(R.id.image1);
        Image2 = (ImageView)rootView.findViewById(R.id.image2);
   

        // Inflate the layout for this fragment
        return rootView;
    }
public class SetFragment extends Fragment  {

    View rootView;




    CheckBox white = (CheckBox) rootView.findViewById(R.id.whitebox);
    CheckBox redbox = (CheckBox)rootView.findViewById(R.id.redbox);






    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rootView =  inflater.inflate(R.layout.fragment_set, container, false);

        final CheckBox whitevariable = (CheckBox)rootView.findViewById(R.id.whitebox);
        

  


        return rootView;
    }
위에께 메인 이미지를 보여주는 프래그먼트구요,
아래께 체크박스를 들고있는 프래그먼트인데, 체크박스 프래그먼트에서, 메인프래그먼트 이미지를 제어하려고해요, 체크박스 클릭시에는 이미지 1이 안보여지고 클릭을 해제할때에는 보이는 이런식으로 해서
체크박스1인 이미지1, 체크박스2는 이미지2를 제어하려고하는데,

체크박스 프래그먼트에서, 체크박스를 만들기만해도 에러가나요 ㅠ
rootView =  inflater.inflate(R.layout.fragment_set, container, false)

이부분들을 View가 아닌 LinearLayout 같은걸로 하면 될 거 같네요.

[fragment_set.xml]
<Linear>
  <CheckBox>
</Linear>

View로 하신 이유가 있나요?

아 그리고 Linear로 바꾸셨으면
LinearLayout  rootView =  (LinearLayout)inflater.inflate(R.layout.fragment_set, container, false);

이렇게 가시면 되요
오 ㅠㅠㅠ 이제 체크박스 변수받아도 안튕기네요 ㅠㅠㅠㅠ 그럼 값은 어떻게 넘겨줘요?? 찾아보니 Bundle을 통해서 넘겨주면 되나요??
...