In AndroidManifest.xml宣告如下:
.... <RadioGroup android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:checkedButton="@+id/horizontalRB" android:gravity="center_horizontal" > <RadioButton android:layout_width="wrap_content" android:layout_height="fill_parent" android:text="@string/hor" android:textColor="@color/black" android:id="@id/horizontalRB" /> <RadioButton android:layout_width="wrap_content" android:layout_height="fill_parent" android:textColor="@color/black" android:text="@string/ver" android:id="@+id/verticalRB" /> RadioGroup> ...
在java程式中取值,用Intent帶值putExtra呼叫其他Activity。
RadioButton rb1=(RadioButton)findViewById(R.id.horizontalRB); RadioButton rb2=(RadioButton)findViewById(R.id.verticalRB); Intent intent = new Intent(); if (rb2.isChecked()) intent.putExtra("vertical",true); else intent.putExtra("vertical",false); intent.setClass(getBaseContext(), main.class); startActivity(intent);
沒有留言:
張貼留言