카카오톡의 메뉴와 레이아웃과 같은 형식으로 제작하려고 합니다
3개의 라디오버튼과 3개의 액티비티가 있습니다
라디오 버튼중 하나는 checked = true 로 주었구요
RadioButton rb_human, rb_msg, rb_other;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rb_human = (RadioButton)findViewById(R.id.rb_human);
rb_msg = (RadioButton)findViewById(R.id.rb_msg);
rb_other = (RadioButton)findViewById(R.id.rb_other);
rb_human.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Sub_1 sub_1 = new Sub_1();
transaction.replace(R.id.layout_main, sub_1);
transaction.commit();
}
});
rb_msg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Sub_2 sub_2 = new Sub_2();
transaction.replace(R.id.layout_main, sub_2);
transaction.commit();
}
});
rb_other.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Sub_3 sub_3 = new Sub_3();
transaction.replace(R.id.layout_main, sub_3);
transaction.commit();
}
});
이게 메인 액티비티의 java 코드입니다 앱 실행하였을때 체크되어있는 버튼의 fragment 를 불러오고싶습니다
<RadioGroup
android:id="@+id/rb_mainmenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginTop="30dp"
android:layout_weight="1">
<RadioButton
android:id="@+id/rb_human"
android:layout_width="50dp"
android:layout_height="40dp"
android:width="50dp"
android:height="50dp"
android:background="@drawable/imgtoggle_human"
android:button="@null"
android:checked="true" />
<RadioButton
android:id="@+id/rb_msg"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="@drawable/imgtoggle_message"
android:button="@null"
android:scaleType="fitXY" />
<RadioButton
android:id="@+id/rb_other"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="3dp"
android:background="@drawable/imgtoggle_other"
android:button="@null"
android:scaleType="fitXY" />
</RadioGroup>
이건 라디오 그룹의 xml 코드이구요 메인 xml 의 화면에 체크되어서 불러올 화면을 메인화면에 미리 넣어두어야 하는건가요? 아니면 체크되어있는 라디오버튼의 fragment 를 앱 실행시 불러올수있는 방법이 있을까요 ?