안드로이드 개발 질문/답변
(글 수 45,052)
라디오 버튼의 선택에 따라
다음 Activity의 레이아웃을 바꾸려고 하는데요
Activity가 넘어가면 예상치 못한 종료가 떠요 ㅠㅠ
고수님들 도와주세요 ㅠㅠ
소스 올려요~~~
//// 넘겨주는 Activity
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId == R.id.st1_Button) {
btn_next1("1");
}
else if(checkedId == R.id.st2_Button) {
btn_next1("2");
}
}
private void btn_next1(final String a) {
next_btn = (Button)findViewById(R.id.next_Button);
next_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
title = (EditText)findViewById(R.id.edit_title);
Intent st1_intent = new Intent(Menu.this, Onepage.class);
st1_intent.putExtra("numbg", a);
startActivityForResult(st1_intent, 0);
finish();
}
});
}
//// 받는 Activity
Intent intent = getIntent();
String a = intent.getStringExtra("numbg");
if (a=="1") {setContentView(R.layout.onepage);}
else if (a == "2") {setContentView(R.layout.twopage);}
도와주세요 ㅠㅠ
다음 Activity의 레이아웃을 바꾸려고 하는데요
Activity가 넘어가면 예상치 못한 종료가 떠요 ㅠㅠ
고수님들 도와주세요 ㅠㅠ
소스 올려요~~~
//// 넘겨주는 Activity
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(checkedId == R.id.st1_Button) {
btn_next1("1");
}
else if(checkedId == R.id.st2_Button) {
btn_next1("2");
}
}
private void btn_next1(final String a) {
next_btn = (Button)findViewById(R.id.next_Button);
next_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
title = (EditText)findViewById(R.id.edit_title);
Intent st1_intent = new Intent(Menu.this, Onepage.class);
st1_intent.putExtra("numbg", a);
startActivityForResult(st1_intent, 0);
finish();
}
});
}
//// 받는 Activity
Intent intent = getIntent();
String a = intent.getStringExtra("numbg");
if (a=="1") {setContentView(R.layout.onepage);}
else if (a == "2") {setContentView(R.layout.twopage);}
도와주세요 ㅠㅠ
음.. 맞는지는 모르겠지만 한 번 적어 볼께요..
값을 넘겨줄때 라이오버튼을 클릭하면 값을int 1과2 를 넘겨주시고요
받는 엑티비티에서
Intent intent = getIntent();
Bundle myBundle = intent.getExtras();
int a = myBundle.getInt("numbg");
이렇게 해서 switch 구문으로 1일때와 2일때
이미지를 표시하면 되겠네요 .. 궁금한게 정확히 먼지 모르겠네요 ㅎㅎ