
我有一个显示各种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; } }.
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" androID:background="@drawable/carefreebgscaledAlphajpg" ><ScrollVIEw androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" > <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="vertical" androID:ID="@+ID/linearlayoutasscrollneedsonenamedchild" ><TextVIEw 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" /> <TextVIEw androID:ID="@+ID/textVIEwcategory" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:text="category" /> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal" > <RadioGroup xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <Radiobutton androID:ID="@+ID/radiobuttonaccIDent" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="AccIDent" /> <Radiobutton androID:ID="@+ID/radiobuttonincIDent" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="IncIDent" /> <Radiobutton androID:ID="@+ID/radiobuttonconcern" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="Concern" /> </RadioGroup> </linearLayout> <TextVIEw androID:ID="@+ID/textVIEwspacer" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:text="" /> <TextVIEw androID:ID="@+ID/textVIEwtype" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:text="Type" /> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal" > <RadioGroup xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <Radiobutton androID:ID="@+ID/radiobuttonfall" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="Fall" /> <Radiobutton androID:ID="@+ID/radiobuttonTrip" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="Trip" /> <Radiobutton androID:ID="@+ID/radiobuttonillness" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="Illness" /> </RadioGroup> </linearLayout> <TextVIEw androID:ID="@+ID/textVIEwspacer2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:text="" /> <TextVIEw androID:ID="@+ID/textVIEwaction" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:text="Action" /> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal" > <RadioGroup xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <Radiobutton androID:ID="@+ID/radiobuttonCallDoctor" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="Call Doctor" /> <Radiobutton androID:ID="@+ID/radiobuttoncalledkin" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:text="Called next of kin" /> </RadioGroup> </linearLayout> <TextVIEw androID:ID="@+ID/textVIEwspacer3" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:text="" /> <TextVIEw androID:ID="@+ID/textVIEwresolution" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textAppearance="?androID:attr/textAppearanceMedium" androID:text="Resolution" /> <EditText androID:ID="@+ID/editTextresolution" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:ems="1" androID:lines="8" androID:inputType="textMultiline" > <requestFocus /> </EditText> <button androID:ID="@+ID/buttonsubmit" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_gravity="center" androID:text="submit" /> </linearLayout></ScrollVIEw> </linearLayout>解决方法:
试试这样: –
RadioGroup group = (RadioGroup) findVIEwByID(R.ID.radioGroup1);group.setonChecked@R_419_1962@(new OnChecked@R_419_1962@() { @OverrIDe public voID onCheckedChanged(RadioGroup group, int checkedID) { // Todo auto-generated method stub if(radiobutton1.isChecked()) { fall.setVisibility(VIEw.GONE); trip.setVisibility(VIEw.GONE); illness.setVisibility(VIEw.GONE); } else if(radiobutton2.isChecked()) { } }}); 总结 以上是内存溢出为你收集整理的java – 如何将侦听器附加到单选按钮全部内容,希望文章能够帮你解决java – 如何将侦听器附加到单选按钮所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)