JAVA单选组监听_java – 如何将侦听器附加到单选按钮

我有一个显示各种radiobutton的活动.无线电按钮分组在无线电组中.我希望在检查某个单选按钮时,一些radiobutton会消失.例如,当检查事故按钮时,摔倒,绊倒和疾病的无线电按钮消失.我怎么能实现这个目标?

我有愚蠢的代码,但需要以某种方式将监听器附加到事件按钮.

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.reportsomethinglayout);

resolution = (EditText)findViewById(R.id.editTextresolution);

// resolution.setInputType(InputType.TYPE_NULL);

// showSoftKeyboard(resolution);

accident = (RadioButton)findViewById(R.id.radioButtonaccident);

incident = (RadioButton)findViewById(R.id.radioButtonincident);

concern = (RadioButton)findViewById(R.id.radioButtonconcern);

fall = (RadioButton)findViewById(R.id.radioButtonfall);

trip = (RadioButton)findViewById(R.id.radioButtonTrip);

illness = (RadioButton)findViewById(R.id.radioButtonillness);

}

public void onRadioButtonClicked(View view) {

// Is the button now checked?

boolean checked = ((RadioButton) view).isChecked();

// Check which radio button was clicked

switch(view.getId()) {

case R.id.radioButtonaccident:

if (checked)

Log.e(TAG, "accident radiobutton checked");

break;

case R.id.radioButtonincident:

if (checked)

Log.e(TAG, "incident radiobutton checked");

fall.setVisibility(View.GONE);

trip.setVisibility(View.GONE);

illness.setVisibility(View.GONE);

break;

}

}

.

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:background="@drawable/carefreebgscaledalphajpg" >

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

android:id="@+id/linearlayoutasscrollneedsonenamedchild" >

android:id="@+id/reportsomethingtitletextview"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Carer Reporting"

android:textAppearance="?android:attr/textAppearanceLarge"

android:layout_gravity="center" />

android:id="@+id/textViewcategory"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="Category" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:id="@+id/radioButtonaccident"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Accident" />

android:id="@+id/radioButtonincident"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Incident" />

android:id="@+id/radioButtonconcern"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Concern" />

android:id="@+id/textViewspacer"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="" />

android:id="@+id/textViewtype"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="Type" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:id="@+id/radioButtonfall"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Fall" />

android:id="@+id/radioButtonTrip"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Trip" />

android:id="@+id/radioButtonillness"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Illness" />

android:id="@+id/textViewspacer2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="" />

android:id="@+id/textViewaction"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="Action" />

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="horizontal">

android:id="@+id/radioButtonCallDoctor"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Call Doctor" />

android:id="@+id/radioButtoncalledkin"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Called next of kin" />

android:id="@+id/textViewspacer3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="" />

android:id="@+id/textViewresolution"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="Resolution" />

android:id="@+id/editTextresolution"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:ems="1"

android:lines="8"

android:inputType="textMultiLine"

>

android:id="@+id/buttonsubmit"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_gravity="center"

android:text="Submit" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值