마스터Q&A
접속유지
가입하기
안드로이드 Q&A
최근 질문
미답변 질문
태그
사용자
질문하기
마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다.
안드로이드펍
에서 운영하고 있습니다. [
사용법
,
운영진
]
인기있는 태그
초보어플개발
(3427)
안드로이드스튜디오
(2664)
안드로이드-초보어플개발
(1333)
안드로이드-스튜디오
(1086)
도와주세요-
(995)
이미지
(970)
listview
(866)
리스트뷰
(844)
오류
(805)
레이아웃
(693)
fragment
(675)
webview
(670)
프래그먼트 사용, 체크박스 사용시 전달이 안될때.
0
추천
프래그먼트가 지금 현재 3개가 있습니다.
Main화면을 보여주는 MainFragment
Image를 보여주는 Image프래그먼트
그래고 체크박스를 담고있는 CheckFragment가 있는데,
체크박스를 선택하여 이미지를 보여주고 안보여주고를 하려는데
이게 체크박스를 선언하거나 할때마다 자꾸 응답없음 종료가 나오는데
어떻게 해야하나요 ㅠ
프래그먼트
초보개발
체크박스
익명사용자
님이
2017년 6월 13일
질문
Please
log in
or
register
to add a comment.
답변 달기
·
글에 소스 코드 보기 좋게 넣는 법
·
질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
답변이 채택되거나 답변에 댓글이 달리면 이메일로 알려드립니다:
답변이 채택되거나 댓글이 달리면 이메일로 알려드립니다
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면
로그인
하거나 혹은
가입
하세요.
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을 통해서 넘겨주면 되나요??
Please
log in
or
register
to add a comment.
...